Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(29)

Delta Between Two Patch Sets: src/pkg/http/cgi/child_test.go

Issue 4432079: code review 4432079: cgi: set Request.TLS and Request.RemoteAddr for children (Closed)
Left Patch Set: Created 13 years, 10 months ago
Right Patch Set: diff -r d93b5329ae9f https://go.googlecode.com/hg Created 13 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/http/cgi/child.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Tests for CGI (the child process perspective) 5 // Tests for CGI (the child process perspective)
6 6
7 package cgi 7 package cgi
8 8
9 import ( 9 import (
10 "testing" 10 "testing"
11 ) 11 )
12 12
13 func TestRequest(t *testing.T) { 13 func TestRequest(t *testing.T) {
14 env := map[string]string{ 14 env := map[string]string{
15 "SERVER_PROTOCOL": "HTTP/1.1", 15 "SERVER_PROTOCOL": "HTTP/1.1",
16 "REQUEST_METHOD": "GET", 16 "REQUEST_METHOD": "GET",
17 "HTTP_HOST": "example.com", 17 "HTTP_HOST": "example.com",
18 "HTTP_REFERER": "elsewhere", 18 "HTTP_REFERER": "elsewhere",
19 "HTTP_USER_AGENT": "goclient", 19 "HTTP_USER_AGENT": "goclient",
20 "HTTP_FOO_BAR": "baz", 20 "HTTP_FOO_BAR": "baz",
21 "REQUEST_URI": "/path?a=b", 21 "REQUEST_URI": "/path?a=b",
22 "CONTENT_LENGTH": "123", 22 "CONTENT_LENGTH": "123",
23 "HTTPS": "1",
24 "REMOTE_ADDR": "5.6.7.8",
23 } 25 }
24 req, err := RequestFromMap(env) 26 req, err := RequestFromMap(env)
25 if err != nil { 27 if err != nil {
26 t.Fatalf("RequestFromMap: %v", err) 28 t.Fatalf("RequestFromMap: %v", err)
27 } 29 }
28 if g, e := req.UserAgent, "goclient"; e != g { 30 if g, e := req.UserAgent, "goclient"; e != g {
29 t.Errorf("expected UserAgent %q; got %q", e, g) 31 t.Errorf("expected UserAgent %q; got %q", e, g)
30 } 32 }
31 if g, e := req.Method, "GET"; e != g { 33 if g, e := req.Method, "GET"; e != g {
32 t.Errorf("expected Method %q; got %q", e, g) 34 t.Errorf("expected Method %q; got %q", e, g)
(...skipping 19 matching lines...) Expand all
52 } 54 }
53 if g, e := req.URL.String(), "http://example.com/path?a=b"; e != g { 55 if g, e := req.URL.String(), "http://example.com/path?a=b"; e != g {
54 t.Errorf("expected URL %q; got %q", e, g) 56 t.Errorf("expected URL %q; got %q", e, g)
55 } 57 }
56 if g, e := req.FormValue("a"), "b"; e != g { 58 if g, e := req.FormValue("a"), "b"; e != g {
57 t.Errorf("expected FormValue(a) %q; got %q", e, g) 59 t.Errorf("expected FormValue(a) %q; got %q", e, g)
58 } 60 }
59 if req.Trailer == nil { 61 if req.Trailer == nil {
60 t.Errorf("unexpected nil Trailer") 62 t.Errorf("unexpected nil Trailer")
61 } 63 }
64 if req.TLS == nil {
65 t.Errorf("expected non-nil TLS")
66 }
67 if e, g := "5.6.7.8:0", req.RemoteAddr; e != g {
68 t.Errorf("RemoteAddr: got %q; want %q", g, e)
69 }
62 } 70 }
63 71
64 func TestRequestWithoutHost(t *testing.T) { 72 func TestRequestWithoutHost(t *testing.T) {
65 env := map[string]string{ 73 env := map[string]string{
66 "SERVER_PROTOCOL": "HTTP/1.1", 74 "SERVER_PROTOCOL": "HTTP/1.1",
67 "HTTP_HOST": "", 75 "HTTP_HOST": "",
68 "REQUEST_METHOD": "GET", 76 "REQUEST_METHOD": "GET",
69 "REQUEST_URI": "/path?a=b", 77 "REQUEST_URI": "/path?a=b",
70 "CONTENT_LENGTH": "123", 78 "CONTENT_LENGTH": "123",
71 } 79 }
72 req, err := RequestFromMap(env) 80 req, err := RequestFromMap(env)
73 if err != nil { 81 if err != nil {
74 t.Fatalf("RequestFromMap: %v", err) 82 t.Fatalf("RequestFromMap: %v", err)
75 } 83 }
76 if g, e := req.RawURL, "/path?a=b"; e != g { 84 if g, e := req.RawURL, "/path?a=b"; e != g {
77 t.Errorf("expected RawURL %q; got %q", e, g) 85 t.Errorf("expected RawURL %q; got %q", e, g)
78 } 86 }
79 if req.URL == nil { 87 if req.URL == nil {
80 t.Fatalf("unexpected nil URL") 88 t.Fatalf("unexpected nil URL")
81 } 89 }
82 if g, e := req.URL.String(), "/path?a=b"; e != g { 90 if g, e := req.URL.String(), "/path?a=b"; e != g {
83 t.Errorf("expected URL %q; got %q", e, g) 91 t.Errorf("expected URL %q; got %q", e, g)
84 } 92 }
85 } 93 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b