]> Cypherpunks repositories - gostls13.git/commitdiff
net/http/fcgi: Request.Body should always be non-nil
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 20 Mar 2013 16:06:33 +0000 (09:06 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 20 Mar 2013 16:06:33 +0000 (09:06 -0700)
Found this inconsistency from net/http's Server while
debugging Issue 4183

Unfortunately this package lacks testing around this,
or most of child.go. :/

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7735046

src/pkg/net/http/fcgi/child.go

index e647f9391e458d61e95da93d6c6f3779ccc62387..f36abbcca3a9e962fe0db79e1735592ab5013a7d 100644 (file)
@@ -10,10 +10,12 @@ import (
        "errors"
        "fmt"
        "io"
+       "io/ioutil"
        "net"
        "net/http"
        "net/http/cgi"
        "os"
+       "strings"
        "time"
 )
 
@@ -152,6 +154,8 @@ func (c *child) serve() {
 
 var errCloseConn = errors.New("fcgi: connection should be closed")
 
+var emptyBody = ioutil.NopCloser(strings.NewReader(""))
+
 func (c *child) handleRecord(rec *record) error {
        req, ok := c.requests[rec.h.Id]
        if !ok && rec.h.Type != typeBeginRequest && rec.h.Type != typeGetValues {
@@ -191,6 +195,8 @@ func (c *child) handleRecord(rec *record) error {
                                // body could be an io.LimitReader, but it shouldn't matter
                                // as long as both sides are behaving.
                                body, req.pw = io.Pipe()
+                       } else {
+                               body = emptyBody
                        }
                        go c.serveRequest(req, body)
                }
@@ -232,9 +238,7 @@ func (c *child) serveRequest(req *request, body io.ReadCloser) {
                httpReq.Body = body
                c.handler.ServeHTTP(r, httpReq)
        }
-       if body != nil {
-               body.Close()
-       }
+       body.Close()
        r.Close()
        c.conn.writeEndRequest(req.reqId, 0, statusRequestComplete)
        if !req.keepConn {