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

Delta Between Two Patch Sets: src/net/http/httputil/dump_test.go

Issue 144650044: code review 144650044: net/http/httputil: ensure DumpRequestOut dumps all of Body (Closed)
Left Patch Set: Created 10 years, 5 months ago
Right Patch Set: diff -r b0e30135710173e2af2140fc019d408bcd1b45ab https://go.googlecode.com/hg/ Created 10 years, 5 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/net/http/httputil/dump.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 package httputil 5 package httputil
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "io" 10 "io"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 Body: []byte("abcdef"), 104 Body: []byte("abcdef"),
105 105
106 WantDumpOut: "POST / HTTP/1.1\r\n" + 106 WantDumpOut: "POST / HTTP/1.1\r\n" +
107 "Host: post.tld\r\n" + 107 "Host: post.tld\r\n" +
108 "User-Agent: Go 1.1 package http\r\n" + 108 "User-Agent: Go 1.1 package http\r\n" +
109 "Content-Length: 6\r\n" + 109 "Content-Length: 6\r\n" +
110 "Accept-Encoding: gzip\r\n\r\n", 110 "Accept-Encoding: gzip\r\n\r\n",
111 111
112 NoBody: true, 112 NoBody: true,
113 }, 113 },
114
115 // Request with Body > 8196 (default buffer size)
116 {
117 Req: http.Request{
118 Method: "POST",
119 URL: &url.URL{
120 Scheme: "http",
121 Host: "post.tld",
122 Path: "/",
123 },
124 ContentLength: 8193,
125 ProtoMajor: 1,
126 ProtoMinor: 1,
127 },
128
129 Body: bytes.Repeat([]byte("a"), 8193),
130
131 WantDumpOut: "POST / HTTP/1.1\r\n" +
132 "Host: post.tld\r\n" +
133 "User-Agent: Go 1.1 package http\r\n" +
134 "Content-Length: 8193\r\n" +
135 "Accept-Encoding: gzip\r\n\r\n" +
136 strings.Repeat("a", 8193),
137 },
114 } 138 }
115 139
116 func TestDumpRequest(t *testing.T) { 140 func TestDumpRequest(t *testing.T) {
117 numg0 := runtime.NumGoroutine() 141 numg0 := runtime.NumGoroutine()
118 for i, tt := range dumpTests { 142 for i, tt := range dumpTests {
119 setBody := func() { 143 setBody := func() {
120 if tt.Body == nil { 144 if tt.Body == nil {
121 return 145 return
122 } 146 }
123 switch b := tt.Body.(type) { 147 switch b := tt.Body.(type) {
124 case []byte: 148 case []byte:
125 tt.Req.Body = ioutil.NopCloser(bytes.NewReader(b )) 149 tt.Req.Body = ioutil.NopCloser(bytes.NewReader(b ))
126 case func() io.ReadCloser: 150 case func() io.ReadCloser:
127 tt.Req.Body = b() 151 tt.Req.Body = b()
152 default:
153 t.Fatalf("Test %d: unsupported Body of %T", i, t t.Body)
128 } 154 }
129 } 155 }
130 setBody() 156 setBody()
131 if tt.Req.Header == nil { 157 if tt.Req.Header == nil {
132 tt.Req.Header = make(http.Header) 158 tt.Req.Header = make(http.Header)
133 } 159 }
134 160
135 if tt.WantDump != "" { 161 if tt.WantDump != "" {
136 setBody() 162 setBody()
137 dump, err := DumpRequest(&tt.Req, !tt.NoBody) 163 dump, err := DumpRequest(&tt.Req, !tt.NoBody)
(...skipping 14 matching lines...) Expand all
152 t.Errorf("DumpRequestOut #%d: %s", i, err) 178 t.Errorf("DumpRequestOut #%d: %s", i, err)
153 continue 179 continue
154 } 180 }
155 if string(dump) != tt.WantDumpOut { 181 if string(dump) != tt.WantDumpOut {
156 t.Errorf("DumpRequestOut %d, expecting:\n%s\nGot :\n%s\n", i, tt.WantDumpOut, string(dump)) 182 t.Errorf("DumpRequestOut %d, expecting:\n%s\nGot :\n%s\n", i, tt.WantDumpOut, string(dump))
157 continue 183 continue
158 } 184 }
159 } 185 }
160 } 186 }
161 if dg := runtime.NumGoroutine() - numg0; dg > 4 { 187 if dg := runtime.NumGoroutine() - numg0; dg > 4 {
162 » » t.Errorf("Unexpectedly large number of new goroutines: %d new", dg) 188 » » buf := make([]byte, 4096)
189 » » buf = buf[:runtime.Stack(buf, true)]
190 » » t.Errorf("Unexpectedly large number of new goroutines: %d new: % s", dg, buf)
163 } 191 }
164 } 192 }
165 193
166 func chunk(s string) string { 194 func chunk(s string) string {
167 return fmt.Sprintf("%x\r\n%s\r\n", len(s), s) 195 return fmt.Sprintf("%x\r\n%s\r\n", len(s), s)
168 } 196 }
169 197
170 func mustParseURL(s string) *url.URL { 198 func mustParseURL(s string) *url.URL {
171 u, err := url.Parse(s) 199 u, err := url.Parse(s)
172 if err != nil { 200 if err != nil {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 282 }
255 got := string(gotb) 283 got := string(gotb)
256 got = strings.TrimSpace(got) 284 got = strings.TrimSpace(got)
257 got = strings.Replace(got, "\r", "", -1) 285 got = strings.Replace(got, "\r", "", -1)
258 286
259 if got != tt.want { 287 if got != tt.want {
260 t.Errorf("%d.\nDumpResponse got:\n%s\n\nWant:\n%s\n", i, got, tt.want) 288 t.Errorf("%d.\nDumpResponse got:\n%s\n\nWant:\n%s\n", i, got, tt.want)
261 } 289 }
262 } 290 }
263 } 291 }
LEFTRIGHT

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