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.
26 var reqTests = []reqTest{
27 // Baseline test; All Request fields included for template use
29 "GET http://www.techcrunch.com/ HTTP/1.1\r\n" +
30 "Host: www.techcrunch.com\r\n" +
31 "User-Agent: Fake\r\n" +
32 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" +
33 "Accept-Language: en-us,en;q=0.5\r\n" +
34 "Accept-Encoding: gzip,deflate\r\n" +
35 "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" +
36 "Keep-Alive: 300\r\n" +
37 "Content-Length: 7\r\n" +
38 "Proxy-Connection: keep-alive\r\n\r\n" +
44 Raw: "http://www.techcrunch.com/",
47 RawAuthority: "www.techcrunch.com",
49 Host: "www.techcrunch.com",
58 "Accept": {"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"},
59 "Accept-Language": {"en-us,en;q=0.5"},
60 "Accept-Encoding": {"gzip,deflate"},
61 "Accept-Charset": {"ISO-8859-1,utf-8;q=0.7,*;q=0.7"},
62 "Keep-Alive": {"300"},
63 "Proxy-Connection": {"keep-alive"},
64 "Content-Length": {"7"},
65 "User-Agent": {"Fake"},
69 Host: "www.techcrunch.com",
78 // GET request with no body (the normal case)
80 "GET / HTTP/1.1\r\n" +
81 "Host: foo.com\r\n\r\n",
103 // Tests that we don't parse a path that looks like a
104 // scheme-relative URI as a scheme-relative URI.
106 "GET //user@host/is/actually/a/path/ HTTP/1.1\r\n" +
107 "Host: test\r\n\r\n",
112 Raw: "//user@host/is/actually/a/path/",
114 RawPath: "//user@host/is/actually/a/path/",
118 Path: "//user@host/is/actually/a/path/",
136 // Tests a bogus abs_path on the Request-Line (RFC 2616 section 5.1.2)
138 "GET ../../../../etc/passwd HTTP/1.1\r\n" +
139 "Host: test\r\n\r\n",
142 "parse ../../../../etc/passwd: invalid URI for request",
145 // Tests missing URL:
148 "Host: test\r\n\r\n",
155 func TestReadRequest(t *testing.T) {
156 for i := range reqTests {
158 var braw bytes.Buffer
159 braw.WriteString(tt.Raw)
160 req, err := ReadRequest(bufio.NewReader(&braw))
162 if err.String() != tt.Error {
163 t.Errorf("#%d: error %q, want error %q", i, err.String(), tt.Error)
169 diff(t, fmt.Sprintf("#%d Request", i), req, tt.Req)
170 var bout bytes.Buffer
172 io.Copy(&bout, rbody)
175 body := bout.String()
177 t.Errorf("#%d: Body = %q want %q", i, body, tt.Body)