Commit bd21f7f1 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http/fcgi: Request.Body should always be non-nil

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
parent eeb98224
......@@ -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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment