mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
fastcgi: Fix for missing content-length header when using QUIC (#1501)
* Fix for missing content-length header when using QUIC If request.ContentLength is set then it will be used instead of getting it from request.Header map since quic-go(lucas-clemente/quic-go@bb24be8) will not store (and pass) the Content-Length header using its header map. This fixes a potential issue where FastCGI POST requests body empty when QUIC is enabled. (#1370) * Change the data type for fastcgi contentLength to int64 quic-go uses int64 for contentLength * Fix an error for undeclared variable * Fix test for fcgiclient the data type for contentLength
This commit is contained in:
parent
52584f7f23
commit
c62b6b9f1a
3 changed files with 14 additions and 7 deletions
|
@ -91,7 +91,14 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
|
|||
fcgiBackend.SetSendTimeout(rule.SendTimeout)
|
||||
|
||||
var resp *http.Response
|
||||
contentLength, _ := strconv.Atoi(r.Header.Get("Content-Length"))
|
||||
|
||||
var contentLength int64
|
||||
// if ContentLength is already set
|
||||
if r.ContentLength > 0 {
|
||||
contentLength = r.ContentLength
|
||||
} else {
|
||||
contentLength, _ = strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64)
|
||||
}
|
||||
switch r.Method {
|
||||
case "HEAD":
|
||||
resp, err = fcgiBackend.Head(env)
|
||||
|
|
|
@ -112,7 +112,7 @@ type Client interface {
|
|||
Get(pair map[string]string) (response *http.Response, err error)
|
||||
Head(pair map[string]string) (response *http.Response, err error)
|
||||
Options(pairs map[string]string) (response *http.Response, err error)
|
||||
Post(pairs map[string]string, method string, bodyType string, body io.Reader, contentLength int) (response *http.Response, err error)
|
||||
Post(pairs map[string]string, method string, bodyType string, body io.Reader, contentLength int64) (response *http.Response, err error)
|
||||
Close() error
|
||||
StdErr() bytes.Buffer
|
||||
SetReadTimeout(time.Duration) error
|
||||
|
@ -493,7 +493,7 @@ 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, method 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 int64) (resp *http.Response, err error) {
|
||||
if p == nil {
|
||||
p = make(map[string]string)
|
||||
}
|
||||
|
@ -504,7 +504,7 @@ func (c *FCGIClient) Post(p map[string]string, method string, bodyType string, b
|
|||
p["REQUEST_METHOD"] = "POST"
|
||||
}
|
||||
|
||||
p["CONTENT_LENGTH"] = strconv.Itoa(l)
|
||||
p["CONTENT_LENGTH"] = strconv.FormatInt(l, 10)
|
||||
if len(bodyType) > 0 {
|
||||
p["CONTENT_TYPE"] = bodyType
|
||||
} else {
|
||||
|
@ -518,7 +518,7 @@ func (c *FCGIClient) Post(p map[string]string, method string, bodyType string, b
|
|||
// 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, "POST", "application/x-www-form-urlencoded", body, body.Len())
|
||||
return c.Post(p, "POST", "application/x-www-form-urlencoded", body, int64(body.Len()))
|
||||
}
|
||||
|
||||
// PostFile issues a POST to the fcgi responder in multipart(RFC 2046) standard,
|
||||
|
@ -560,7 +560,7 @@ func (c *FCGIClient) PostFile(p map[string]string, data url.Values, file map[str
|
|||
return
|
||||
}
|
||||
|
||||
return c.Post(p, "POST", bodyType, buf, buf.Len())
|
||||
return c.Post(p, "POST", bodyType, buf, int64(buf.Len()))
|
||||
}
|
||||
|
||||
// SetReadTimeout sets the read timeout for future calls that read from the
|
||||
|
|
|
@ -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, int64(rd.Len()))
|
||||
} else if len(posts) > 0 {
|
||||
values := url.Values{}
|
||||
for k, v := range posts {
|
||||
|
|
Loading…
Reference in a new issue