OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 http_test | 5 package http_test |
6 | 6 |
7 import ( | 7 import ( |
8 "bufio" | 8 "bufio" |
9 "bytes" | 9 "bytes" |
10 "fmt" | 10 "fmt" |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 return len(p), nil | 282 return len(p), nil |
283 } | 283 } |
284 | 284 |
285 func TestRequestWriteBufferedWriter(t *testing.T) { | 285 func TestRequestWriteBufferedWriter(t *testing.T) { |
286 got := []string{} | 286 got := []string{} |
287 req, _ := NewRequest("GET", "http://foo.com/", nil) | 287 req, _ := NewRequest("GET", "http://foo.com/", nil) |
288 req.Write(logWrites{t, &got}) | 288 req.Write(logWrites{t, &got}) |
289 want := []string{ | 289 want := []string{ |
290 "GET / HTTP/1.1\r\n", | 290 "GET / HTTP/1.1\r\n", |
291 "Host: foo.com\r\n", | 291 "Host: foo.com\r\n", |
292 » » "User-Agent: Go http package\r\n", | 292 » » "User-Agent: " + DefaultUserAgent + "\r\n", |
293 "\r\n", | 293 "\r\n", |
294 } | 294 } |
295 if !reflect.DeepEqual(got, want) { | 295 if !reflect.DeepEqual(got, want) { |
296 t.Errorf("Writes = %q\n Want = %q", got, want) | 296 t.Errorf("Writes = %q\n Want = %q", got, want) |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 func testMissingFile(t *testing.T, req *Request) { | 300 func testMissingFile(t *testing.T, req *Request) { |
301 f, fh, err := req.FormFile("missing") | 301 f, fh, err := req.FormFile("missing") |
302 if f != nil { | 302 if f != nil { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 Connection: keep-alive | 472 Connection: keep-alive |
473 `) | 473 `) |
474 } | 474 } |
475 | 475 |
476 func BenchmarkReadRequestWrk(b *testing.B) { | 476 func BenchmarkReadRequestWrk(b *testing.B) { |
477 // wrk -t 1 -r 1 -c 1 http://localhost:8080/ | 477 // wrk -t 1 -r 1 -c 1 http://localhost:8080/ |
478 benchmarkReadRequest(b, `GET / HTTP/1.1 | 478 benchmarkReadRequest(b, `GET / HTTP/1.1 |
479 Host: localhost:8080 | 479 Host: localhost:8080 |
480 `) | 480 `) |
481 } | 481 } |
OLD | NEW |