Skip to content

Commit

Permalink
use Form instead of Query to also support `application/x-www-form-url…
Browse files Browse the repository at this point in the history
…encoded` for the app provider http endpoint (#3098)
  • Loading branch information
wkloucek authored Jul 25, 2022
1 parent b832b4c commit 05126c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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
22 changes: 16 additions & 6 deletions internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 05126c3

Please sign in to comment.