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

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

Issue 4272045: code review 4272045: http: export Transport, add keep-alive support (Closed)
Left Patch Set: Created 14 years ago
Right Patch Set: diff -r 61121e058bb8 https://go.googlecode.com/hg/ Created 13 years, 11 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/proxy_test.go ('k') | src/pkg/http/transport.go » ('j') | 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 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 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 // End-to-end serving tests 5 // End-to-end serving tests
6 6
7 package http_test 7 package http_test
8 8
9 import ( 9 import (
10 "bufio" 10 "bufio"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 fmt.Fprintf(res, "req=%d", reqNum) 243 fmt.Fprintf(res, "req=%d", reqNum)
244 }) 244 })
245 245
246 const second = 1000000000 /* nanos */ 246 const second = 1000000000 /* nanos */
247 server := &Server{Handler: handler, ReadTimeout: 0.25 * second, WriteTim eout: 0.25 * second} 247 server := &Server{Handler: handler, ReadTimeout: 0.25 * second, WriteTim eout: 0.25 * second}
248 go server.Serve(l) 248 go server.Serve(l)
249 249
250 url := fmt.Sprintf("http://localhost:%d/", addr.Port) 250 url := fmt.Sprintf("http://localhost:%d/", addr.Port)
251 251
252 // Hit the HTTP server successfully. 252 // Hit the HTTP server successfully.
253 » r, _, err := Get(url) 253 » tr := &Transport{DisableKeepAlives: true} // they interfere with this te st
254 » c := &Client{Transport: tr}
255 » r, _, err := c.Get(url)
254 if err != nil { 256 if err != nil {
255 t.Fatalf("http Get #1: %v", err) 257 t.Fatalf("http Get #1: %v", err)
256 } 258 }
257 got, _ := ioutil.ReadAll(r.Body) 259 got, _ := ioutil.ReadAll(r.Body)
258 expected := "req=1" 260 expected := "req=1"
259 if string(got) != expected { 261 if string(got) != expected {
260 t.Errorf("Unexpected response for request #1; got %q; expected % q", 262 t.Errorf("Unexpected response for request #1; got %q; expected % q",
261 string(got), expected) 263 string(got), expected)
262 } 264 }
263 265
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 if cl, expected := res.ContentLength, int64(3); cl != expected { 330 if cl, expected := res.ContentLength, int64(3); cl != expected {
329 t.Errorf("for %s expected res.ContentLength of %d; got % d", url, expected, cl) 331 t.Errorf("for %s expected res.ContentLength of %d; got % d", url, expected, cl)
330 } 332 }
331 if cl, expected := res.Header.Get("Content-Length"), "3"; cl != expected { 333 if cl, expected := res.Header.Get("Content-Length"), "3"; cl != expected {
332 t.Errorf("for %s expected Content-Length header of %q; g ot %q", url, expected, cl) 334 t.Errorf("for %s expected Content-Length header of %q; g ot %q", url, expected, cl)
333 } 335 }
334 if tl, expected := len(res.TransferEncoding), 0; tl != expected { 336 if tl, expected := len(res.TransferEncoding), 0; tl != expected {
335 t.Errorf("for %s expected len(res.TransferEncoding) of % d; got %d (%v)", 337 t.Errorf("for %s expected len(res.TransferEncoding) of % d; got %d (%v)",
336 url, expected, tl, res.TransferEncoding) 338 url, expected, tl, res.TransferEncoding)
337 } 339 }
340 res.Body.Close()
338 } 341 }
339 342
340 // Verify that ErrContentLength is returned 343 // Verify that ErrContentLength is returned
341 url := ts.URL + "/?overwrite=1" 344 url := ts.URL + "/?overwrite=1"
342 _, _, err := Get(url) 345 _, _, err := Get(url)
343 if err != nil { 346 if err != nil {
344 t.Fatalf("error with Get of %s: %v", url, err) 347 t.Fatalf("error with Get of %s: %v", url, err)
345 } 348 }
346
347 // Verify that the connection is closed when the declared Content-Length 349 // Verify that the connection is closed when the declared Content-Length
348 // is larger than what the handler wrote. 350 // is larger than what the handler wrote.
349 conn, err := net.Dial("tcp", "", ts.Listener.Addr().String()) 351 conn, err := net.Dial("tcp", "", ts.Listener.Addr().String())
350 if err != nil { 352 if err != nil {
351 t.Fatalf("error dialing: %v", err) 353 t.Fatalf("error dialing: %v", err)
352 } 354 }
353 _, err = conn.Write([]byte("GET /?underwrite=1 HTTP/1.1\r\nHost: foo\r\n \r\n")) 355 _, err = conn.Write([]byte("GET /?underwrite=1 HTTP/1.1\r\nHost: foo\r\n \r\n"))
354 if err != nil { 356 if err != nil {
355 t.Fatalf("error writing: %v", err) 357 t.Fatalf("error writing: %v", err)
356 } 358 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 if g, e := res.ContentLength, int64(-1); g != e { 445 if g, e := res.ContentLength, int64(-1); g != e {
444 t.Errorf("expected ContentLength of %d; got %d", e, g) 446 t.Errorf("expected ContentLength of %d; got %d", e, g)
445 } 447 }
446 if g, e := res.TransferEncoding, []string{"chunked"}; !reflect.DeepEqual (g, e) { 448 if g, e := res.TransferEncoding, []string{"chunked"}; !reflect.DeepEqual (g, e) {
447 t.Errorf("expected TransferEncoding of %v; got %v", e, g) 449 t.Errorf("expected TransferEncoding of %v; got %v", e, g)
448 } 450 }
449 if _, haveCL := res.Header["Content-Length"]; haveCL { 451 if _, haveCL := res.Header["Content-Length"]; haveCL {
450 t.Errorf("Unexpected Content-Length") 452 t.Errorf("Unexpected Content-Length")
451 } 453 }
452 } 454 }
LEFTRIGHT

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