diff options
author | Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> | 2019-07-18 08:40:10 +0100 |
---|---|---|
committer | Alex Chen <Cnly@users.noreply.github.com> | 2019-07-18 15:40:10 +0800 |
commit | 504d23f468caf6193431f2670c13315b43a84790 (patch) | |
tree | 68a91a9689b973ba17a181ae96350e6a23f8b8a8 /mediaapi | |
parent | bff60953f36f87706546e49cd38fd7fc93727efa (diff) |
Remove unnecessary http method checks (#747)
Closes #523
There were a lot of unnecessary checks for HTTP methods of requests. gorilla/mux makes sure that these methods will only be called if certain HTTP methods are used, thus there's no reason to have these extra checks.
Diffstat (limited to 'mediaapi')
-rw-r--r-- | mediaapi/routing/download.go | 10 | ||||
-rw-r--r-- | mediaapi/routing/upload.go | 9 |
2 files changed, 2 insertions, 17 deletions
diff --git a/mediaapi/routing/download.go b/mediaapi/routing/download.go index 38c43636..80ad8418 100644 --- a/mediaapi/routing/download.go +++ b/mediaapi/routing/download.go @@ -55,7 +55,7 @@ type downloadRequest struct { Logger *log.Entry } -// Download implements /download amd /thumbnail +// Download implements GET /download and GET /thumbnail // Files from this server (i.e. origin == cfg.ServerName) are served directly // Files from remote servers (i.e. origin != cfg.ServerName) are cached locally. // If they are present in the cache, they are served directly. @@ -107,14 +107,6 @@ func Download( } // request validation - if req.Method != http.MethodGet { - dReq.jsonErrorResponse(w, util.JSONResponse{ - Code: http.StatusMethodNotAllowed, - JSON: jsonerror.Unknown("request method must be GET"), - }) - return - } - if resErr := dReq.Validate(); resErr != nil { dReq.jsonErrorResponse(w, *resErr) return diff --git a/mediaapi/routing/upload.go b/mediaapi/routing/upload.go index 1051e0e0..2cb0d875 100644 --- a/mediaapi/routing/upload.go +++ b/mediaapi/routing/upload.go @@ -48,7 +48,7 @@ type uploadResponse struct { ContentURI string `json:"content_uri"` } -// Upload implements /upload +// Upload implements POST /upload // This endpoint involves uploading potentially significant amounts of data to the homeserver. // This implementation supports a configurable maximum file size limit in bytes. If a user tries to upload more than this, they will receive an error that their upload is too large. // Uploaded files are processed piece-wise to avoid DoS attacks which would starve the server of memory. @@ -75,13 +75,6 @@ func Upload(req *http.Request, cfg *config.Dendrite, db *storage.Database, activ // all the metadata about the media being uploaded. // Returns either an uploadRequest or an error formatted as a util.JSONResponse func parseAndValidateRequest(req *http.Request, cfg *config.Dendrite) (*uploadRequest, *util.JSONResponse) { - if req.Method != http.MethodPost { - return nil, &util.JSONResponse{ - Code: http.StatusMethodNotAllowed, - JSON: jsonerror.Unknown("HTTP request method must be POST."), - } - } - r := &uploadRequest{ MediaMetadata: &types.MediaMetadata{ Origin: cfg.Matrix.ServerName, |