Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions middleware/fastcgi/fastcgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 9 additions & 27 deletions middleware/fastcgi/fcgiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion middleware/fastcgi/fcgiclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down