~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): Serge Hallyn
  • Date: 2014-11-18 15:12:26 UTC
  • mfrom: (14.2.12 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20141118151226-zug7vn93mn3dtiz3
Tags: 2:1.3.2-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - Support co-installability with gccgo-go tool:
    - d/rules,golang-go.install: Rename bin/go -> bin/golang-go
    - d/golang-go.{postinst,prerm}: Install/remove /usr/bin/go using
      alternatives.
  - d/copyright: Amendments for full compiliance with copyright format.
  - d/control: Demote golang-go.tools to Suggests to support Ubuntu MIR.
  - dropped patches (now upstream):
    - d/p/issue27650045_40001_50001.diff
    - d/p/issue28050043_60001_70001.diff
    - d/p/issue54790044_100001_110001.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
import (
8
8
        "bytes"
9
9
        "io/ioutil"
 
10
        "strings"
10
11
        "testing"
11
12
)
12
13
 
25
26
                                ProtoMinor:    0,
26
27
                                Request:       dummyReq("GET"),
27
28
                                Header:        Header{},
28
 
                                Body:          ioutil.NopCloser(bytes.NewBufferString("abcdef")),
 
29
                                Body:          ioutil.NopCloser(strings.NewReader("abcdef")),
29
30
                                ContentLength: 6,
30
31
                        },
31
32
 
41
42
                                ProtoMinor:    0,
42
43
                                Request:       dummyReq("GET"),
43
44
                                Header:        Header{},
44
 
                                Body:          ioutil.NopCloser(bytes.NewBufferString("abcdef")),
 
45
                                Body:          ioutil.NopCloser(strings.NewReader("abcdef")),
45
46
                                ContentLength: -1,
46
47
                        },
47
48
                        "HTTP/1.0 200 OK\r\n" +
48
49
                                "\r\n" +
49
50
                                "abcdef",
50
51
                },
 
52
                // HTTP/1.1 response with unknown length and Connection: close
 
53
                {
 
54
                        Response{
 
55
                                StatusCode:    200,
 
56
                                ProtoMajor:    1,
 
57
                                ProtoMinor:    1,
 
58
                                Request:       dummyReq("GET"),
 
59
                                Header:        Header{},
 
60
                                Body:          ioutil.NopCloser(strings.NewReader("abcdef")),
 
61
                                ContentLength: -1,
 
62
                                Close:         true,
 
63
                        },
 
64
                        "HTTP/1.1 200 OK\r\n" +
 
65
                                "Connection: close\r\n" +
 
66
                                "\r\n" +
 
67
                                "abcdef",
 
68
                },
 
69
                // HTTP/1.1 response with unknown length and not setting connection: close
 
70
                {
 
71
                        Response{
 
72
                                StatusCode:    200,
 
73
                                ProtoMajor:    1,
 
74
                                ProtoMinor:    1,
 
75
                                Request:       dummyReq11("GET"),
 
76
                                Header:        Header{},
 
77
                                Body:          ioutil.NopCloser(strings.NewReader("abcdef")),
 
78
                                ContentLength: -1,
 
79
                                Close:         false,
 
80
                        },
 
81
                        "HTTP/1.1 200 OK\r\n" +
 
82
                                "Connection: close\r\n" +
 
83
                                "\r\n" +
 
84
                                "abcdef",
 
85
                },
 
86
                // HTTP/1.1 response with unknown length and not setting connection: close, but
 
87
                // setting chunked.
 
88
                {
 
89
                        Response{
 
90
                                StatusCode:       200,
 
91
                                ProtoMajor:       1,
 
92
                                ProtoMinor:       1,
 
93
                                Request:          dummyReq11("GET"),
 
94
                                Header:           Header{},
 
95
                                Body:             ioutil.NopCloser(strings.NewReader("abcdef")),
 
96
                                ContentLength:    -1,
 
97
                                TransferEncoding: []string{"chunked"},
 
98
                                Close:            false,
 
99
                        },
 
100
                        "HTTP/1.1 200 OK\r\n" +
 
101
                                "Transfer-Encoding: chunked\r\n\r\n" +
 
102
                                "6\r\nabcdef\r\n0\r\n\r\n",
 
103
                },
 
104
                // HTTP/1.1 response 0 content-length, and nil body
 
105
                {
 
106
                        Response{
 
107
                                StatusCode:    200,
 
108
                                ProtoMajor:    1,
 
109
                                ProtoMinor:    1,
 
110
                                Request:       dummyReq11("GET"),
 
111
                                Header:        Header{},
 
112
                                Body:          nil,
 
113
                                ContentLength: 0,
 
114
                                Close:         false,
 
115
                        },
 
116
                        "HTTP/1.1 200 OK\r\n" +
 
117
                                "Content-Length: 0\r\n" +
 
118
                                "\r\n",
 
119
                },
 
120
                // HTTP/1.1 response 0 content-length, and non-nil empty body
 
121
                {
 
122
                        Response{
 
123
                                StatusCode:    200,
 
124
                                ProtoMajor:    1,
 
125
                                ProtoMinor:    1,
 
126
                                Request:       dummyReq11("GET"),
 
127
                                Header:        Header{},
 
128
                                Body:          ioutil.NopCloser(strings.NewReader("")),
 
129
                                ContentLength: 0,
 
130
                                Close:         false,
 
131
                        },
 
132
                        "HTTP/1.1 200 OK\r\n" +
 
133
                                "Content-Length: 0\r\n" +
 
134
                                "\r\n",
 
135
                },
 
136
                // HTTP/1.1 response 0 content-length, and non-nil non-empty body
 
137
                {
 
138
                        Response{
 
139
                                StatusCode:    200,
 
140
                                ProtoMajor:    1,
 
141
                                ProtoMinor:    1,
 
142
                                Request:       dummyReq11("GET"),
 
143
                                Header:        Header{},
 
144
                                Body:          ioutil.NopCloser(strings.NewReader("foo")),
 
145
                                ContentLength: 0,
 
146
                                Close:         false,
 
147
                        },
 
148
                        "HTTP/1.1 200 OK\r\n" +
 
149
                                "Connection: close\r\n" +
 
150
                                "\r\nfoo",
 
151
                },
51
152
                // HTTP/1.1, chunked coding; empty trailer; close
52
153
                {
53
154
                        Response{
56
157
                                ProtoMinor:       1,
57
158
                                Request:          dummyReq("GET"),
58
159
                                Header:           Header{},
59
 
                                Body:             ioutil.NopCloser(bytes.NewBufferString("abcdef")),
 
160
                                Body:             ioutil.NopCloser(strings.NewReader("abcdef")),
60
161
                                ContentLength:    6,
61
162
                                TransferEncoding: []string{"chunked"},
62
163
                                Close:            true,
90
191
                                "Foo: Bar Baz\r\n" +
91
192
                                "\r\n",
92
193
                },
 
194
 
 
195
                // Want a single Content-Length header. Fixing issue 8180 where
 
196
                // there were two.
 
197
                {
 
198
                        Response{
 
199
                                StatusCode:       StatusOK,
 
200
                                ProtoMajor:       1,
 
201
                                ProtoMinor:       1,
 
202
                                Request:          &Request{Method: "POST"},
 
203
                                Header:           Header{},
 
204
                                ContentLength:    0,
 
205
                                TransferEncoding: nil,
 
206
                                Body:             nil,
 
207
                        },
 
208
                        "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n",
 
209
                },
93
210
        }
94
211
 
95
212
        for i := range respWriteTests {