mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-24 01:26:47 +01:00
Merge pull request #636 from humboldtux/fastcgi-cl
fastcgi: Explicitly set Content-Length (fixes #626)
This commit is contained in:
commit
a2dbfdc10e
1 changed files with 10 additions and 1 deletions
11
middleware/fastcgi/fastcgi.go
Executable file → Normal file
11
middleware/fastcgi/fastcgi.go
Executable file → Normal file
|
@ -4,6 +4,7 @@
|
||||||
package fastcgi
|
package fastcgi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -105,13 +106,21 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
|
||||||
return http.StatusBadGateway, err
|
return http.StatusBadGateway, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write the response body to a buffer
|
||||||
|
// To explicitly set Content-Length
|
||||||
|
// For FastCGI app that don't set it
|
||||||
|
var buf bytes.Buffer
|
||||||
|
io.Copy(&buf, resp.Body)
|
||||||
|
if r.Header.Get("Content-Length") == "" {
|
||||||
|
w.Header().Set("Content-Length", strconv.Itoa(buf.Len()))
|
||||||
|
}
|
||||||
writeHeader(w, resp)
|
writeHeader(w, resp)
|
||||||
|
|
||||||
// Write the response body
|
// Write the response body
|
||||||
// TODO: If this has an error, the response will already be
|
// TODO: If this has an error, the response will already be
|
||||||
// partly written. We should copy out of resp.Body into a buffer
|
// partly written. We should copy out of resp.Body into a buffer
|
||||||
// first, then write it to the response...
|
// first, then write it to the response...
|
||||||
_, err = io.Copy(w, resp.Body)
|
_, err = io.Copy(w, &buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusBadGateway, err
|
return http.StatusBadGateway, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue