diff --git a/middleware/fastcgi/fastcgi.go b/middleware/fastcgi/fastcgi.go index 33b21d4359c..302bea35587 100755 --- a/middleware/fastcgi/fastcgi.go +++ b/middleware/fastcgi/fastcgi.go @@ -85,16 +85,8 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) resp, err = fcgiBackend.Get(env) case "OPTIONS": resp, err = fcgiBackend.Options(env) - case "POST": - resp, err = fcgiBackend.Post(env, r.Header.Get("Content-Type"), r.Body, contentLength) - case "PUT": - resp, err = fcgiBackend.Put(env, r.Header.Get("Content-Type"), r.Body, contentLength) - case "PATCH": - resp, err = fcgiBackend.Patch(env, r.Header.Get("Content-Type"), r.Body, contentLength) - case "DELETE": - resp, err = fcgiBackend.Delete(env, r.Header.Get("Content-Type"), r.Body, contentLength) default: - return http.StatusMethodNotAllowed, nil + resp, err = fcgiBackend.Post(env, r.Method, r.Header.Get("Content-Type"), r.Body, contentLength) } if resp.Body != nil { diff --git a/middleware/fastcgi/fcgiclient.go b/middleware/fastcgi/fcgiclient.go index 82580137c97..7f7f82e9cf7 100644 --- a/middleware/fastcgi/fcgiclient.go +++ b/middleware/fastcgi/fcgiclient.go @@ -489,11 +489,17 @@ func (c *FCGIClient) Options(p map[string]string) (resp *http.Response, err erro // Post issues a POST request to the fcgi responder. with request body // in the format that bodyType specified -func (c *FCGIClient) Post(p map[string]string, bodyType string, body io.Reader, l int) (resp *http.Response, err error) { +func (c *FCGIClient) Post(p map[string]string, method string, bodyType string, body io.Reader, l int) (resp *http.Response, err error) { + if p == nil { + p = make(map[string]string) + } + + p["REQUEST_METHOD"] = strings.ToUpper(method) if len(p["REQUEST_METHOD"]) == 0 || p["REQUEST_METHOD"] == "GET" { p["REQUEST_METHOD"] = "POST" } + p["CONTENT_LENGTH"] = strconv.Itoa(l) if len(bodyType) > 0 { p["CONTENT_TYPE"] = bodyType @@ -504,35 +510,11 @@ func (c *FCGIClient) Post(p map[string]string, bodyType string, body io.Reader, return c.Request(p, body) } -// Put issues a PUT request to the fcgi responder. -func (c *FCGIClient) Put(p map[string]string, bodyType string, body io.Reader, l int) (resp *http.Response, err error) { - - p["REQUEST_METHOD"] = "PUT" - - return c.Post(p, bodyType, body, l) -} - -// Patch issues a PATCH request to the fcgi responder. -func (c *FCGIClient) Patch(p map[string]string, bodyType string, body io.Reader, l int) (resp *http.Response, err error) { - - p["REQUEST_METHOD"] = "PATCH" - - return c.Post(p, bodyType, body, l) -} - -// Delete issues a DELETE request to the fcgi responder. -func (c *FCGIClient) Delete(p map[string]string, bodyType string, body io.Reader, l int) (resp *http.Response, err error) { - - p["REQUEST_METHOD"] = "DELETE" - - return c.Post(p, bodyType, body, l) -} - // PostForm issues a POST to the fcgi responder, with form // as a string key to a list values (url.Values) func (c *FCGIClient) PostForm(p map[string]string, data url.Values) (resp *http.Response, err error) { body := bytes.NewReader([]byte(data.Encode())) - return c.Post(p, "application/x-www-form-urlencoded", body, body.Len()) + return c.Post(p, "POST", "application/x-www-form-urlencoded", body, body.Len()) } // PostFile issues a POST to the fcgi responder in multipart(RFC 2046) standard, @@ -571,7 +553,7 @@ func (c *FCGIClient) PostFile(p map[string]string, data url.Values, file map[str return } - return c.Post(p, bodyType, buf, buf.Len()) + return c.Post(p, "POST", bodyType, buf, buf.Len()) } // Checks whether chunked is part of the encodings stack diff --git a/middleware/fastcgi/fcgiclient_test.go b/middleware/fastcgi/fcgiclient_test.go index 0eeebb4b162..04a01c524c2 100644 --- a/middleware/fastcgi/fcgiclient_test.go +++ b/middleware/fastcgi/fcgiclient_test.go @@ -117,7 +117,7 @@ func sendFcgi(reqType int, fcgiParams map[string]string, data []byte, posts map[ if len(data) > 0 { length = len(data) rd := bytes.NewReader(data) - resp, err = fcgi.Post(fcgiParams, "", rd, rd.Len()) + resp, err = fcgi.Post(fcgiParams, "", "", rd, rd.Len()) } else if len(posts) > 0 { values := url.Values{} for k, v := range posts {