mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-08 11:58:49 +03:00
fastcgi: Accept any other methods as a POST-style request
This commit is contained in:
parent
c5983e305f
commit
600ee9a89f
3 changed files with 11 additions and 37 deletions
|
@ -85,16 +85,8 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
|
|||
resp, err = fcgi.Get(env)
|
||||
case "OPTIONS":
|
||||
resp, err = fcgi.Options(env)
|
||||
case "POST":
|
||||
resp, err = fcgi.Post(env, r.Header.Get("Content-Type"), r.Body, contentLength)
|
||||
case "PUT":
|
||||
resp, err = fcgi.Put(env, r.Header.Get("Content-Type"), r.Body, contentLength)
|
||||
case "PATCH":
|
||||
resp, err = fcgi.Patch(env, r.Header.Get("Content-Type"), r.Body, contentLength)
|
||||
case "DELETE":
|
||||
resp, err = fcgi.Delete(env, r.Header.Get("Content-Type"), r.Body, contentLength)
|
||||
default:
|
||||
return http.StatusMethodNotAllowed, nil
|
||||
resp, err = fcgi.Post(env, r.Method, r.Header.Get("Content-Type"), r.Body, contentLength)
|
||||
}
|
||||
|
||||
if resp.Body != nil {
|
||||
|
|
|
@ -484,11 +484,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
|
||||
|
@ -499,35 +505,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,
|
||||
|
@ -566,7 +548,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
|
||||
|
|
|
@ -119,7 +119,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 {
|
||||
|
|
Loading…
Reference in a new issue