diff --git a/changelog/unreleased/enhancement-app-provider-form-instead-query.md b/changelog/unreleased/enhancement-app-provider-form-instead-query.md new file mode 100644 index 0000000000..96d78fea2f --- /dev/null +++ b/changelog/unreleased/enhancement-app-provider-form-instead-query.md @@ -0,0 +1,7 @@ +Enhancement: app provider http endpoint uses Form instead of Query + +We've improved the http endpoint now uses the Form instead of Query +to also support `application/x-www-form-urlencoded` parameters on + the app provider http endpoint. + +https://github.com/cs3org/reva/pull/3098 diff --git a/internal/http/services/appprovider/appprovider.go b/internal/http/services/appprovider/appprovider.go index eafe54ba80..3b8f44e525 100644 --- a/internal/http/services/appprovider/appprovider.go +++ b/internal/http/services/appprovider/appprovider.go @@ -123,13 +123,18 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) { return } - if r.URL.Query().Get("template") != "" { + err = r.ParseForm() + if err != nil { + writeError(w, r, appErrorInvalidParameter, "parameters could not be parsed", nil) + } + + if r.Form.Get("template") != "" { // TODO in the future we want to create a file out of the given template writeError(w, r, appErrorUnimplemented, "template is not implemented", nil) return } - parentContainerIDStr := r.URL.Query().Get("parent_container_id") + parentContainerIDStr := r.Form.Get("parent_container_id") if parentContainerIDStr == "" { writeError(w, r, appErrorInvalidParameter, "missing parent container ID", nil) return @@ -141,7 +146,7 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) { return } - filename := r.URL.Query().Get("filename") + filename := r.Form.Get("filename") if filename == "" { writeError(w, r, appErrorInvalidParameter, "missing filename", nil) return @@ -328,7 +333,12 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) { return } - fileID := r.URL.Query().Get("file_id") + err = r.ParseForm() + if err != nil { + writeError(w, r, appErrorInvalidParameter, "parameters could not be parsed", nil) + } + + fileID := r.Form.Get("file_id") if fileID == "" { writeError(w, r, appErrorInvalidParameter, "missing file ID", nil) @@ -365,7 +375,7 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) { return } - viewMode := getViewMode(statRes.Info, r.URL.Query().Get("view_mode")) + viewMode := getViewMode(statRes.Info, r.Form.Get("view_mode")) if viewMode == gateway.OpenInAppRequest_VIEW_MODE_INVALID { writeError(w, r, appErrorInvalidParameter, "invalid view mode", err) return @@ -374,7 +384,7 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) { openReq := gateway.OpenInAppRequest{ Ref: fileRef, ViewMode: viewMode, - App: r.URL.Query().Get("app_name"), + App: r.Form.Get("app_name"), } openRes, err := client.OpenInApp(ctx, &openReq) if err != nil {