File tree Expand file tree Collapse file tree
modules/caddyhttp/reverseproxy/fastcgi Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ import (
4141
4242 "go.uber.org/zap"
4343 "go.uber.org/zap/zapcore"
44+
45+ "github.com/caddyserver/caddy/v2/modules/caddyhttp"
4446)
4547
4648// FCGIListenSockFileno describes listen socket file number.
@@ -136,6 +138,15 @@ type client struct {
136138// Do made the request and returns a io.Reader that translates the data read
137139// from fcgi responder out of fcgi packet before returning it.
138140func (c * client ) Do (p map [string ]string , req io.Reader ) (r io.Reader , err error ) {
141+ // check for CONTENT_LENGTH, since the lack of it or wrong value will cause the backend to hang
142+ if clStr , ok := p ["CONTENT_LENGTH" ]; ! ok {
143+ return nil , caddyhttp .Error (http .StatusLengthRequired , nil )
144+ } else if _ , err := strconv .ParseUint (clStr , 10 , 64 ); err != nil {
145+ // stdlib won't return a negative Content-Length, but we check just in case,
146+ // the most likely cause is from a missing content length, which is -1
147+ return nil , caddyhttp .Error (http .StatusLengthRequired , err )
148+ }
149+
139150 writer := & streamWriter {c : c }
140151 writer .buf = bufPool .Get ().(* bytes.Buffer )
141152 writer .buf .Reset ()
You can’t perform that action at this time.
0 commit comments