aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/http/readrequest_test.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2011-11-03 13:26:43 -0700
committerRob Pike <r@golang.org>2011-11-03 13:26:43 -0700
commitde03d502c7e0bd07c6f084ed9b5bb0446df29b49 (patch)
tree4f6d5a7248cfa5419f637393a4bc674aa05ffaf5 /src/pkg/http/readrequest_test.go
parent5cb4a15320d3b2ac121e3c68249c8ac403120bad (diff)
downloadgo-de03d502c7e0bd07c6f084ed9b5bb0446df29b49.tar.xz
net: renamings
This is Go 1 package renaming CL #3. This one merely moves the source; the import strings will be changed after the next weekly release. This one moves pieces into net. http -> net/http http/cgi -> net/http/cgi http/fcgi -> net/http/fcgi http/pprof -> net/http/pprof http/httptest -> net/http/httptest mail -> net/mail rpc -> net/rpc rpc/jsonrpc -> net/rpc/jsonrpc smtp -> net/smtp url -> net/url Also remove rand (now math/rand) from NOTEST - it has a test. The only edits are in Makefiles and deps.bash. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5335048
Diffstat (limited to 'src/pkg/http/readrequest_test.go')
-rw-r--r--src/pkg/http/readrequest_test.go180
1 files changed, 0 insertions, 180 deletions
diff --git a/src/pkg/http/readrequest_test.go b/src/pkg/http/readrequest_test.go
deleted file mode 100644
index d62133df43..0000000000
--- a/src/pkg/http/readrequest_test.go
+++ /dev/null
@@ -1,180 +0,0 @@
-// Copyright 2010 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package http
-
-import (
- "bufio"
- "bytes"
- "fmt"
- "io"
- "testing"
- "url"
-)
-
-type reqTest struct {
- Raw string
- Req *Request
- Body string
- Error string
-}
-
-var noError = ""
-var noBody = ""
-
-var reqTests = []reqTest{
- // Baseline test; All Request fields included for template use
- {
- "GET http://www.techcrunch.com/ HTTP/1.1\r\n" +
- "Host: www.techcrunch.com\r\n" +
- "User-Agent: Fake\r\n" +
- "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" +
- "Accept-Language: en-us,en;q=0.5\r\n" +
- "Accept-Encoding: gzip,deflate\r\n" +
- "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" +
- "Keep-Alive: 300\r\n" +
- "Content-Length: 7\r\n" +
- "Proxy-Connection: keep-alive\r\n\r\n" +
- "abcdef\n???",
-
- &Request{
- Method: "GET",
- URL: &url.URL{
- Raw: "http://www.techcrunch.com/",
- Scheme: "http",
- RawPath: "/",
- RawAuthority: "www.techcrunch.com",
- RawUserinfo: "",
- Host: "www.techcrunch.com",
- Path: "/",
- RawQuery: "",
- Fragment: "",
- },
- Proto: "HTTP/1.1",
- ProtoMajor: 1,
- ProtoMinor: 1,
- Header: Header{
- "Accept": {"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"},
- "Accept-Language": {"en-us,en;q=0.5"},
- "Accept-Encoding": {"gzip,deflate"},
- "Accept-Charset": {"ISO-8859-1,utf-8;q=0.7,*;q=0.7"},
- "Keep-Alive": {"300"},
- "Proxy-Connection": {"keep-alive"},
- "Content-Length": {"7"},
- "User-Agent": {"Fake"},
- },
- Close: false,
- ContentLength: 7,
- Host: "www.techcrunch.com",
- Form: url.Values{},
- },
-
- "abcdef\n",
-
- noError,
- },
-
- // GET request with no body (the normal case)
- {
- "GET / HTTP/1.1\r\n" +
- "Host: foo.com\r\n\r\n",
-
- &Request{
- Method: "GET",
- URL: &url.URL{
- Raw: "/",
- Path: "/",
- RawPath: "/",
- },
- Proto: "HTTP/1.1",
- ProtoMajor: 1,
- ProtoMinor: 1,
- Close: false,
- ContentLength: 0,
- Host: "foo.com",
- Form: url.Values{},
- },
-
- noBody,
- noError,
- },
-
- // Tests that we don't parse a path that looks like a
- // scheme-relative URI as a scheme-relative URI.
- {
- "GET //user@host/is/actually/a/path/ HTTP/1.1\r\n" +
- "Host: test\r\n\r\n",
-
- &Request{
- Method: "GET",
- URL: &url.URL{
- Raw: "//user@host/is/actually/a/path/",
- Scheme: "",
- RawPath: "//user@host/is/actually/a/path/",
- RawAuthority: "",
- RawUserinfo: "",
- Host: "",
- Path: "//user@host/is/actually/a/path/",
- RawQuery: "",
- Fragment: "",
- },
- Proto: "HTTP/1.1",
- ProtoMajor: 1,
- ProtoMinor: 1,
- Header: Header{},
- Close: false,
- ContentLength: 0,
- Host: "test",
- Form: url.Values{},
- },
-
- noBody,
- noError,
- },
-
- // Tests a bogus abs_path on the Request-Line (RFC 2616 section 5.1.2)
- {
- "GET ../../../../etc/passwd HTTP/1.1\r\n" +
- "Host: test\r\n\r\n",
- nil,
- noBody,
- "parse ../../../../etc/passwd: invalid URI for request",
- },
-
- // Tests missing URL:
- {
- "GET HTTP/1.1\r\n" +
- "Host: test\r\n\r\n",
- nil,
- noBody,
- "parse : empty url",
- },
-}
-
-func TestReadRequest(t *testing.T) {
- for i := range reqTests {
- tt := &reqTests[i]
- var braw bytes.Buffer
- braw.WriteString(tt.Raw)
- req, err := ReadRequest(bufio.NewReader(&braw))
- if err != nil {
- if err.Error() != tt.Error {
- t.Errorf("#%d: error %q, want error %q", i, err.Error(), tt.Error)
- }
- continue
- }
- rbody := req.Body
- req.Body = nil
- diff(t, fmt.Sprintf("#%d Request", i), req, tt.Req)
- var bout bytes.Buffer
- if rbody != nil {
- io.Copy(&bout, rbody)
- rbody.Close()
- }
- body := bout.String()
- if body != tt.Body {
- t.Errorf("#%d: Body = %q want %q", i, body, tt.Body)
- }
- }
-}