~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/net/http/responsewrite_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
        Raw  string
16
16
}
17
17
 
18
 
var respWriteTests = []respWriteTest{
19
 
        // HTTP/1.0, identity coding; no trailer
20
 
        {
21
 
                Response{
22
 
                        StatusCode:    503,
23
 
                        ProtoMajor:    1,
24
 
                        ProtoMinor:    0,
25
 
                        Request:       dummyReq("GET"),
26
 
                        Header:        Header{},
27
 
                        Body:          ioutil.NopCloser(bytes.NewBufferString("abcdef")),
28
 
                        ContentLength: 6,
29
 
                },
30
 
 
31
 
                "HTTP/1.0 503 Service Unavailable\r\n" +
32
 
                        "Content-Length: 6\r\n\r\n" +
33
 
                        "abcdef",
34
 
        },
35
 
        // Unchunked response without Content-Length.
36
 
        {
37
 
                Response{
38
 
                        StatusCode:    200,
39
 
                        ProtoMajor:    1,
40
 
                        ProtoMinor:    0,
41
 
                        Request:       dummyReq("GET"),
42
 
                        Header:        Header{},
43
 
                        Body:          ioutil.NopCloser(bytes.NewBufferString("abcdef")),
44
 
                        ContentLength: -1,
45
 
                },
46
 
                "HTTP/1.0 200 OK\r\n" +
47
 
                        "\r\n" +
48
 
                        "abcdef",
49
 
        },
50
 
        // HTTP/1.1, chunked coding; empty trailer; close
51
 
        {
52
 
                Response{
53
 
                        StatusCode:       200,
54
 
                        ProtoMajor:       1,
55
 
                        ProtoMinor:       1,
56
 
                        Request:          dummyReq("GET"),
57
 
                        Header:           Header{},
58
 
                        Body:             ioutil.NopCloser(bytes.NewBufferString("abcdef")),
59
 
                        ContentLength:    6,
60
 
                        TransferEncoding: []string{"chunked"},
61
 
                        Close:            true,
62
 
                },
63
 
 
64
 
                "HTTP/1.1 200 OK\r\n" +
65
 
                        "Connection: close\r\n" +
66
 
                        "Transfer-Encoding: chunked\r\n\r\n" +
67
 
                        "6\r\nabcdef\r\n0\r\n\r\n",
68
 
        },
69
 
 
70
 
        // Header value with a newline character (Issue 914).
71
 
        // Also tests removal of leading and trailing whitespace.
72
 
        {
73
 
                Response{
74
 
                        StatusCode: 204,
75
 
                        ProtoMajor: 1,
76
 
                        ProtoMinor: 1,
77
 
                        Request:    dummyReq("GET"),
78
 
                        Header: Header{
79
 
                                "Foo": []string{" Bar\nBaz "},
80
 
                        },
81
 
                        Body:             nil,
82
 
                        ContentLength:    0,
83
 
                        TransferEncoding: []string{"chunked"},
84
 
                        Close:            true,
85
 
                },
86
 
 
87
 
                "HTTP/1.1 204 No Content\r\n" +
88
 
                        "Connection: close\r\n" +
89
 
                        "Foo: Bar Baz\r\n" +
90
 
                        "\r\n",
91
 
        },
92
 
}
93
 
 
94
18
func TestResponseWrite(t *testing.T) {
 
19
        respWriteTests := []respWriteTest{
 
20
                // HTTP/1.0, identity coding; no trailer
 
21
                {
 
22
                        Response{
 
23
                                StatusCode:    503,
 
24
                                ProtoMajor:    1,
 
25
                                ProtoMinor:    0,
 
26
                                Request:       dummyReq("GET"),
 
27
                                Header:        Header{},
 
28
                                Body:          ioutil.NopCloser(bytes.NewBufferString("abcdef")),
 
29
                                ContentLength: 6,
 
30
                        },
 
31
 
 
32
                        "HTTP/1.0 503 Service Unavailable\r\n" +
 
33
                                "Content-Length: 6\r\n\r\n" +
 
34
                                "abcdef",
 
35
                },
 
36
                // Unchunked response without Content-Length.
 
37
                {
 
38
                        Response{
 
39
                                StatusCode:    200,
 
40
                                ProtoMajor:    1,
 
41
                                ProtoMinor:    0,
 
42
                                Request:       dummyReq("GET"),
 
43
                                Header:        Header{},
 
44
                                Body:          ioutil.NopCloser(bytes.NewBufferString("abcdef")),
 
45
                                ContentLength: -1,
 
46
                        },
 
47
                        "HTTP/1.0 200 OK\r\n" +
 
48
                                "\r\n" +
 
49
                                "abcdef",
 
50
                },
 
51
                // HTTP/1.1, chunked coding; empty trailer; close
 
52
                {
 
53
                        Response{
 
54
                                StatusCode:       200,
 
55
                                ProtoMajor:       1,
 
56
                                ProtoMinor:       1,
 
57
                                Request:          dummyReq("GET"),
 
58
                                Header:           Header{},
 
59
                                Body:             ioutil.NopCloser(bytes.NewBufferString("abcdef")),
 
60
                                ContentLength:    6,
 
61
                                TransferEncoding: []string{"chunked"},
 
62
                                Close:            true,
 
63
                        },
 
64
 
 
65
                        "HTTP/1.1 200 OK\r\n" +
 
66
                                "Connection: close\r\n" +
 
67
                                "Transfer-Encoding: chunked\r\n\r\n" +
 
68
                                "6\r\nabcdef\r\n0\r\n\r\n",
 
69
                },
 
70
 
 
71
                // Header value with a newline character (Issue 914).
 
72
                // Also tests removal of leading and trailing whitespace.
 
73
                {
 
74
                        Response{
 
75
                                StatusCode: 204,
 
76
                                ProtoMajor: 1,
 
77
                                ProtoMinor: 1,
 
78
                                Request:    dummyReq("GET"),
 
79
                                Header: Header{
 
80
                                        "Foo": []string{" Bar\nBaz "},
 
81
                                },
 
82
                                Body:             nil,
 
83
                                ContentLength:    0,
 
84
                                TransferEncoding: []string{"chunked"},
 
85
                                Close:            true,
 
86
                        },
 
87
 
 
88
                        "HTTP/1.1 204 No Content\r\n" +
 
89
                                "Connection: close\r\n" +
 
90
                                "Foo: Bar Baz\r\n" +
 
91
                                "\r\n",
 
92
                },
 
93
        }
 
94
 
95
95
        for i := range respWriteTests {
96
96
                tt := &respWriteTests[i]
97
97
                var braw bytes.Buffer