Commit 761f9466 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http/cgi: add an empty response test

New test for http://code.google.com/p/go/source/detail?r=a73ba18

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5701046
parent 68c7e8a2
...@@ -41,6 +41,7 @@ func runCgiTest(t *testing.T, h *Handler, httpreq string, expectedMap map[string ...@@ -41,6 +41,7 @@ func runCgiTest(t *testing.T, h *Handler, httpreq string, expectedMap map[string
// Make a map to hold the test map that the CGI returns. // Make a map to hold the test map that the CGI returns.
m := make(map[string]string) m := make(map[string]string)
m["_body"] = rw.Body.String()
linesRead := 0 linesRead := 0
readlines: readlines:
for { for {
......
...@@ -51,6 +51,22 @@ func TestHostingOurselves(t *testing.T) { ...@@ -51,6 +51,22 @@ func TestHostingOurselves(t *testing.T) {
} }
} }
// Test that a child handler only writing headers works.
func TestChildOnlyHeaders(t *testing.T) {
h := &Handler{
Path: os.Args[0],
Root: "/test.go",
Args: []string{"-test.run=TestBeChildCGIProcess"},
}
expectedMap := map[string]string{
"_body": "",
}
replay := runCgiTest(t, h, "GET /test.go?no-body=1 HTTP/1.0\nHost: example.com\n\n", expectedMap)
if expected, got := "X-Test-Value", replay.Header().Get("X-Test-Header"); got != expected {
t.Errorf("got a X-Test-Header of %q; expected %q", got, expected)
}
}
// Note: not actually a test. // Note: not actually a test.
func TestBeChildCGIProcess(t *testing.T) { func TestBeChildCGIProcess(t *testing.T) {
if os.Getenv("REQUEST_METHOD") == "" { if os.Getenv("REQUEST_METHOD") == "" {
...@@ -59,8 +75,11 @@ func TestBeChildCGIProcess(t *testing.T) { ...@@ -59,8 +75,11 @@ func TestBeChildCGIProcess(t *testing.T) {
} }
Serve(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { Serve(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.Header().Set("X-Test-Header", "X-Test-Value") rw.Header().Set("X-Test-Header", "X-Test-Value")
fmt.Fprintf(rw, "test=Hello CGI-in-CGI\n")
req.ParseForm() req.ParseForm()
if req.FormValue("no-body") == "1" {
return
}
fmt.Fprintf(rw, "test=Hello CGI-in-CGI\n")
for k, vv := range req.Form { for k, vv := range req.Form {
for _, v := range vv { for _, v := range vv {
fmt.Fprintf(rw, "param-%s=%s\n", k, v) fmt.Fprintf(rw, "param-%s=%s\n", k, v)
......
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