1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 type reqWriteTest
struct {
17 var reqWriteTests
= []reqWriteTest
{
18 // HTTP/1.1 => chunked coding; no body; no trailer
22 RawURL
: "http://www.techcrunch.com/",
24 Raw
: "http://www.techcrunch.com/",
26 RawPath
: "http://www.techcrunch.com/",
27 RawAuthority
: "www.techcrunch.com",
29 Host
: "www.techcrunch.com",
37 Header
: map[string]string{
38 "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
39 "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
40 "Accept-Encoding": "gzip,deflate",
41 "Accept-Language": "en-us,en;q=0.5",
43 "Proxy-Connection": "keep-alive",
47 Host
: "www.techcrunch.com",
50 Form
: map[string][]string{},
53 "GET http://www.techcrunch.com/ HTTP/1.1\r\n" +
54 "Host: www.techcrunch.com\r\n" +
55 "User-Agent: Fake\r\n" +
56 "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" +
57 "Accept-Encoding: gzip,deflate\r\n" +
58 "Accept-Language: en-us,en;q=0.5\r\n" +
59 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" +
60 "Keep-Alive: 300\r\n" +
61 "Proxy-Connection: keep-alive\r\n\r\n",
63 // HTTP/1.1 => chunked coding; body; empty trailer
69 Host
: "www.google.com",
74 Header
: map[string]string{},
75 Body
: nopCloser
{bytes
.NewBufferString("abcdef")},
76 TransferEncoding
: []string{"chunked"},
79 "GET /search HTTP/1.1\r\n" +
80 "Host: www.google.com\r\n" +
81 "User-Agent: Go http package\r\n" +
82 "Transfer-Encoding: chunked\r\n\r\n" +
83 "6\r\nabcdef\r\n0\r\n\r\n",
85 // HTTP/1.1 POST => chunked coding; body; empty trailer
91 Host
: "www.google.com",
96 Header
: map[string]string{},
98 Body
: nopCloser
{bytes
.NewBufferString("abcdef")},
99 TransferEncoding
: []string{"chunked"},
102 "POST /search HTTP/1.1\r\n" +
103 "Host: www.google.com\r\n" +
104 "User-Agent: Go http package\r\n" +
105 "Connection: close\r\n" +
106 "Transfer-Encoding: chunked\r\n\r\n" +
107 "6\r\nabcdef\r\n0\r\n\r\n",
109 // default to HTTP/1.1
114 Host
: "www.google.com",
117 "GET /search HTTP/1.1\r\n" +
118 "Host: www.google.com\r\n" +
119 "User-Agent: Go http package\r\n" +
124 func TestRequestWrite(t
*testing
.T
) {
125 for i
:= range reqWriteTests
{
126 tt
:= &reqWriteTests
[i
]
127 var braw bytes
.Buffer
128 err
:= tt
.Req
.Write(&braw
)
130 t
.Errorf("error writing #%d: %s", i
, err
)
133 sraw
:= braw
.String()
135 t
.Errorf("Test %d, expecting:\n%s\nGot:\n%s\n", i
, tt
.Raw
, sraw
)