Merge lp:~pedronis/ubuntu-push/update-http13 into lp:ubuntu-push
- update-http13
- Merge into trunk
Proposed by
Samuele Pedroni
Status: | Superseded |
---|---|
Proposed branch: | lp:~pedronis/ubuntu-push/update-http13 |
Merge into: | lp:ubuntu-push |
Diff against target: |
6384 lines (+2600/-1451) 48 files modified
bus/endpoint.go (+4/-4) bus/testing/testing_endpoint_test.go (+1/-1) client/client.go (+64/-27) client/client_test.go (+69/-19) client/service/common.go (+99/-0) client/service/postal.go (+122/-0) client/service/postal_test.go (+191/-0) client/service/service.go (+53/-165) client/service/service_test.go (+44/-136) client/session/session.go (+6/-17) client/session/session_test.go (+15/-28) debian/changelog (+25/-0) debian/config.json (+3/-1) debian/rules (+0/-1) http13client/Makefile (+2/-1) http13client/_patches/empty_server.patch (+118/-42) http13client/_patches/fix_code.patch (+73/-65) http13client/_patches/fix_status.patch (+33/-20) http13client/_patches/fix_tests.patch (+338/-384) http13client/_using.txt (+3/-3) http13client/client.go (+11/-3) http13client/client_test.go (+92/-0) http13client/cookie.go (+19/-37) http13client/cookie_test.go (+0/-304) http13client/request.go (+62/-50) http13client/request_test.go (+48/-8) http13client/response.go (+52/-5) http13client/response_test.go (+4/-0) http13client/responsewrite_test.go (+117/-1) http13client/server.go (+11/-5) http13client/transfer.go (+59/-27) http13client/transport.go (+114/-42) http13client/transport_test.go (+296/-17) nih/nih.go (+1/-1) scripts/dummyauth.sh (+3/-0) scripts/register (+43/-0) scripts/unicast (+2/-0) server/acceptance/acceptanceclient.go (+1/-1) server/acceptance/cmd/acceptanceclient.go (+3/-1) server/acceptance/suites/suite.go (+2/-2) server/acceptance/suites/unicast.go (+11/-3) server/api/handlers.go (+104/-8) server/api/handlers_test.go (+193/-2) server/store/inmemory.go (+26/-0) server/store/inmemory_test.go (+44/-0) server/store/store.go (+8/-0) signing-helper/signing-helper.cpp (+6/-10) whoopsie/identifier/identifier.go (+5/-10) |
To merge this branch: | bzr merge lp:~pedronis/ubuntu-push/update-http13 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Push Hackers | Pending | ||
Review via email: mp+223915@code.launchpad.net |
Commit message
update http13client from the actual go1.3 release
Description of the change
update http13client from the actual go1.3 release
To post a comment you must log in.
- 187. By Samuele Pedroni
-
changelog
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bus/endpoint.go' | |||
2 | --- bus/endpoint.go 2014-05-15 11:28:06 +0000 | |||
3 | +++ bus/endpoint.go 2014-06-20 13:02:58 +0000 | |||
4 | @@ -29,7 +29,7 @@ | |||
5 | 29 | * Endpoint (and its implementation) | 29 | * Endpoint (and its implementation) |
6 | 30 | */ | 30 | */ |
7 | 31 | 31 | ||
9 | 32 | type BusMethod func([]interface{}, []interface{}) ([]interface{}, error) | 32 | type BusMethod func(string, []interface{}, []interface{}) ([]interface{}, error) |
10 | 33 | type DispatchMap map[string]BusMethod | 33 | type DispatchMap map[string]BusMethod |
11 | 34 | 34 | ||
12 | 35 | // bus.Endpoint represents the DBus connection itself. | 35 | // bus.Endpoint represents the DBus connection itself. |
13 | @@ -249,12 +249,12 @@ | |||
14 | 249 | endp.log.Errorf("WatchMethod: unknown method %s", msg.Member) | 249 | endp.log.Errorf("WatchMethod: unknown method %s", msg.Member) |
15 | 250 | } else { | 250 | } else { |
16 | 251 | args := msg.AllArgs() | 251 | args := msg.AllArgs() |
18 | 252 | rvals, err := meth(args, extra) | 252 | rvals, err := meth(string(msg.Path), args, extra) |
19 | 253 | if err != nil { | 253 | if err != nil { |
20 | 254 | reply = dbus.NewErrorMessage(msg, err_iface, err.Error()) | 254 | reply = dbus.NewErrorMessage(msg, err_iface, err.Error()) |
22 | 255 | endp.log.Errorf("WatchMethod: %s(%#v, %#v) failure: %#v", msg.Member, args, extra, err) | 255 | endp.log.Errorf("WatchMethod: %s(%v, %#v, %#v) failure: %#v", msg.Member, msg.Path, args, extra, err) |
23 | 256 | } else { | 256 | } else { |
25 | 257 | endp.log.Debugf("WatchMethod: %s(%#v, %#v) success: %#v", msg.Member, args, extra, rvals) | 257 | endp.log.Debugf("WatchMethod: %s(%v, %#v, %#v) success: %#v", msg.Member, msg.Path, args, extra, rvals) |
26 | 258 | reply = dbus.NewMethodReturnMessage(msg) | 258 | reply = dbus.NewMethodReturnMessage(msg) |
27 | 259 | err = reply.AppendArgs(rvals...) | 259 | err = reply.AppendArgs(rvals...) |
28 | 260 | if err != nil { | 260 | if err != nil { |
29 | 261 | 261 | ||
30 | === modified file 'bus/testing/testing_endpoint_test.go' | |||
31 | --- bus/testing/testing_endpoint_test.go 2014-06-02 10:04:34 +0000 | |||
32 | +++ bus/testing/testing_endpoint_test.go 2014-06-20 13:02:58 +0000 | |||
33 | @@ -229,7 +229,7 @@ | |||
34 | 229 | // Test that WatchMethod updates callArgs | 229 | // Test that WatchMethod updates callArgs |
35 | 230 | func (s *TestingEndpointSuite) TestWatchMethodUpdatesCallArgs(c *C) { | 230 | func (s *TestingEndpointSuite) TestWatchMethodUpdatesCallArgs(c *C) { |
36 | 231 | endp := NewTestingEndpoint(nil, condition.Work(true)) | 231 | endp := NewTestingEndpoint(nil, condition.Work(true)) |
38 | 232 | foo := func([]interface{}, []interface{}) ([]interface{}, error) { return nil, nil } | 232 | foo := func(string, []interface{}, []interface{}) ([]interface{}, error) { return nil, nil } |
39 | 233 | foomp := bus.DispatchMap{"foo": foo} | 233 | foomp := bus.DispatchMap{"foo": foo} |
40 | 234 | endp.WatchMethod(foomp) | 234 | endp.WatchMethod(foomp) |
41 | 235 | c.Check(GetCallArgs(endp), DeepEquals, []callArgs{ | 235 | c.Check(GetCallArgs(endp), DeepEquals, []callArgs{ |
42 | 236 | 236 | ||
43 | === modified file 'client/client.go' | |||
44 | --- client/client.go 2014-05-21 10:03:18 +0000 | |||
45 | +++ client/client.go 2014-06-20 13:02:58 +0000 | |||
46 | @@ -28,6 +28,7 @@ | |||
47 | 28 | "fmt" | 28 | "fmt" |
48 | 29 | "io/ioutil" | 29 | "io/ioutil" |
49 | 30 | "os" | 30 | "os" |
50 | 31 | "os/exec" | ||
51 | 31 | "strings" | 32 | "strings" |
52 | 32 | 33 | ||
53 | 33 | "launchpad.net/go-dbus/v1" | 34 | "launchpad.net/go-dbus/v1" |
54 | @@ -63,32 +64,36 @@ | |||
55 | 63 | // The PEM-encoded server certificate | 64 | // The PEM-encoded server certificate |
56 | 64 | CertPEMFile string `json:"cert_pem_file"` | 65 | CertPEMFile string `json:"cert_pem_file"` |
57 | 65 | // How to invoke the auth helper | 66 | // How to invoke the auth helper |
59 | 66 | AuthHelper []string `json:"auth_helper"` | 67 | AuthHelper string `json:"auth_helper"` |
60 | 68 | SessionURL string `json:"session_url"` | ||
61 | 69 | RegistrationURL string `json:"registration_url"` | ||
62 | 67 | // The logging level (one of "debug", "info", "error") | 70 | // The logging level (one of "debug", "info", "error") |
63 | 68 | LogLevel logger.ConfigLogLevel `json:"log_level"` | 71 | LogLevel logger.ConfigLogLevel `json:"log_level"` |
64 | 69 | } | 72 | } |
65 | 70 | 73 | ||
66 | 71 | // PushClient is the Ubuntu Push Notifications client-side daemon. | 74 | // PushClient is the Ubuntu Push Notifications client-side daemon. |
67 | 72 | type PushClient struct { | 75 | type PushClient struct { |
87 | 73 | leveldbPath string | 76 | leveldbPath string |
88 | 74 | configPath string | 77 | configPath string |
89 | 75 | config ClientConfig | 78 | config ClientConfig |
90 | 76 | log logger.Logger | 79 | log logger.Logger |
91 | 77 | pem []byte | 80 | pem []byte |
92 | 78 | idder identifier.Id | 81 | idder identifier.Id |
93 | 79 | deviceId string | 82 | deviceId string |
94 | 80 | notificationsEndp bus.Endpoint | 83 | notificationsEndp bus.Endpoint |
95 | 81 | urlDispatcherEndp bus.Endpoint | 84 | urlDispatcherEndp bus.Endpoint |
96 | 82 | connectivityEndp bus.Endpoint | 85 | connectivityEndp bus.Endpoint |
97 | 83 | systemImageEndp bus.Endpoint | 86 | systemImageEndp bus.Endpoint |
98 | 84 | systemImageInfo *systemimage.InfoResult | 87 | systemImageInfo *systemimage.InfoResult |
99 | 85 | connCh chan bool | 88 | connCh chan bool |
100 | 86 | hasConnectivity bool | 89 | hasConnectivity bool |
101 | 87 | actionsCh <-chan notifications.RawActionReply | 90 | actionsCh <-chan notifications.RawActionReply |
102 | 88 | session *session.ClientSession | 91 | session *session.ClientSession |
103 | 89 | sessionConnectedCh chan uint32 | 92 | sessionConnectedCh chan uint32 |
104 | 90 | serviceEndpoint bus.Endpoint | 93 | pushServiceEndpoint bus.Endpoint |
105 | 91 | service *service.Service | 94 | pushService *service.PushService |
106 | 95 | postalServiceEndpoint bus.Endpoint | ||
107 | 96 | postalService *service.PostalService | ||
108 | 92 | } | 97 | } |
109 | 93 | 98 | ||
110 | 94 | var ( | 99 | var ( |
111 | @@ -160,7 +165,27 @@ | |||
112 | 160 | ExpectAllRepairedTime: client.config.ExpectAllRepairedTime.TimeDuration(), | 165 | ExpectAllRepairedTime: client.config.ExpectAllRepairedTime.TimeDuration(), |
113 | 161 | PEM: client.pem, | 166 | PEM: client.pem, |
114 | 162 | Info: info, | 167 | Info: info, |
116 | 163 | AuthHelper: client.config.AuthHelper, | 168 | AuthGetter: client.getAuthorization, |
117 | 169 | AuthURL: client.config.SessionURL, | ||
118 | 170 | } | ||
119 | 171 | } | ||
120 | 172 | |||
121 | 173 | // getAuthorization gets the authorization blob to send to the server | ||
122 | 174 | func (client *PushClient) getAuthorization(url string) string { | ||
123 | 175 | client.log.Debugf("getting authorization for %s", url) | ||
124 | 176 | // using a helper, for now at least | ||
125 | 177 | if len(client.config.AuthHelper) == 0 { | ||
126 | 178 | // do nothing if helper is unset or empty | ||
127 | 179 | return "" | ||
128 | 180 | } | ||
129 | 181 | |||
130 | 182 | auth, err := exec.Command(client.config.AuthHelper, url).Output() | ||
131 | 183 | if err != nil { | ||
132 | 184 | // For now we just log the error, as we don't want to block unauthorized users | ||
133 | 185 | client.log.Errorf("unable to get the authorization token from the account: %v", err) | ||
134 | 186 | return "" | ||
135 | 187 | } else { | ||
136 | 188 | return strings.TrimSpace(string(auth)) | ||
137 | 164 | } | 189 | } |
138 | 165 | } | 190 | } |
139 | 166 | 191 | ||
140 | @@ -331,7 +356,7 @@ | |||
141 | 331 | // handleUnicastNotification deals with receiving a unicast notification | 356 | // handleUnicastNotification deals with receiving a unicast notification |
142 | 332 | func (client *PushClient) handleUnicastNotification(msg *protocol.Notification) error { | 357 | func (client *PushClient) handleUnicastNotification(msg *protocol.Notification) error { |
143 | 333 | client.log.Debugf("sending notification %#v for %#v.", msg.MsgId, msg.AppId) | 358 | client.log.Debugf("sending notification %#v for %#v.", msg.MsgId, msg.AppId) |
145 | 334 | return client.service.Inject(msg.AppId, string(msg.Payload)) | 359 | return client.postalService.Inject(msg.AppId, string(msg.Payload)) |
146 | 335 | } | 360 | } |
147 | 336 | 361 | ||
148 | 337 | // handleClick deals with the user clicking a notification | 362 | // handleClick deals with the user clicking a notification |
149 | @@ -422,13 +447,25 @@ | |||
150 | 422 | } | 447 | } |
151 | 423 | 448 | ||
152 | 424 | func (client *PushClient) startService() error { | 449 | func (client *PushClient) startService() error { |
155 | 425 | if client.serviceEndpoint == nil { | 450 | if client.pushServiceEndpoint == nil { |
156 | 426 | client.serviceEndpoint = bus.SessionBus.Endpoint(service.BusAddress, client.log) | 451 | client.pushServiceEndpoint = bus.SessionBus.Endpoint(service.PushServiceBusAddress, client.log) |
157 | 452 | } | ||
158 | 453 | if client.postalServiceEndpoint == nil { | ||
159 | 454 | client.postalServiceEndpoint = bus.SessionBus.Endpoint(service.PostalServiceBusAddress, client.log) | ||
160 | 427 | } | 455 | } |
161 | 428 | 456 | ||
165 | 429 | client.service = service.NewService(client.serviceEndpoint, client.log) | 457 | client.pushService = service.NewPushService(client.pushServiceEndpoint, client.log) |
166 | 430 | client.service.SetMessageHandler(client.messageHandler) | 458 | client.pushService.SetRegistrationURL(client.config.RegistrationURL) |
167 | 431 | return client.service.Start() | 459 | client.pushService.SetAuthGetter(client.getAuthorization) |
168 | 460 | client.postalService = service.NewPostalService(client.postalServiceEndpoint, client.log) | ||
169 | 461 | client.postalService.SetMessageHandler(client.messageHandler) | ||
170 | 462 | if err := client.pushService.Start(); err != nil { | ||
171 | 463 | return err | ||
172 | 464 | } | ||
173 | 465 | if err := client.postalService.Start(); err != nil { | ||
174 | 466 | return err | ||
175 | 467 | } | ||
176 | 468 | return nil | ||
177 | 432 | } | 469 | } |
178 | 433 | 470 | ||
179 | 434 | // Start calls doStart with the "real" starters | 471 | // Start calls doStart with the "real" starters |
180 | 435 | 472 | ||
181 | === modified file 'client/client_test.go' | |||
182 | --- client/client_test.go 2014-05-20 13:56:37 +0000 | |||
183 | +++ client/client_test.go 2014-06-20 13:02:58 +0000 | |||
184 | @@ -103,11 +103,13 @@ | |||
185 | 103 | "stabilizing_timeout": "0ms", | 103 | "stabilizing_timeout": "0ms", |
186 | 104 | "connectivity_check_url": "", | 104 | "connectivity_check_url": "", |
187 | 105 | "connectivity_check_md5": "", | 105 | "connectivity_check_md5": "", |
193 | 106 | "addr": ":0", | 106 | "addr": ":0", |
194 | 107 | "cert_pem_file": pem_file, | 107 | "cert_pem_file": pem_file, |
195 | 108 | "recheck_timeout": "3h", | 108 | "recheck_timeout": "3h", |
196 | 109 | "auth_helper": []string{}, | 109 | "auth_helper": "", |
197 | 110 | "log_level": "debug", | 110 | "session_url": "xyzzy://", |
198 | 111 | "registration_url": "reg://", | ||
199 | 112 | "log_level": "debug", | ||
200 | 111 | } | 113 | } |
201 | 112 | for k, v := range overrides { | 114 | for k, v := range overrides { |
202 | 113 | cfgMap[k] = v | 115 | cfgMap[k] = v |
203 | @@ -257,7 +259,7 @@ | |||
204 | 257 | 259 | ||
205 | 258 | func (cs *clientSuite) TestDeriveSessionConfig(c *C) { | 260 | func (cs *clientSuite) TestDeriveSessionConfig(c *C) { |
206 | 259 | cs.writeTestConfig(map[string]interface{}{ | 261 | cs.writeTestConfig(map[string]interface{}{ |
208 | 260 | "auth_helper": []string{"auth", "helper"}, | 262 | "auth_helper": "auth helper", |
209 | 261 | }) | 263 | }) |
210 | 262 | info := map[string]interface{}{ | 264 | info := map[string]interface{}{ |
211 | 263 | "foo": 1, | 265 | "foo": 1, |
212 | @@ -272,7 +274,8 @@ | |||
213 | 272 | ExpectAllRepairedTime: 30 * time.Minute, | 274 | ExpectAllRepairedTime: 30 * time.Minute, |
214 | 273 | PEM: cli.pem, | 275 | PEM: cli.pem, |
215 | 274 | Info: info, | 276 | Info: info, |
217 | 275 | AuthHelper: []string{"auth", "helper"}, | 277 | AuthGetter: func(string) string { return "" }, |
218 | 278 | AuthURL: "xyzzy://", | ||
219 | 276 | } | 279 | } |
220 | 277 | // sanity check that we are looking at all fields | 280 | // sanity check that we are looking at all fields |
221 | 278 | vExpected := reflect.ValueOf(expected) | 281 | vExpected := reflect.ValueOf(expected) |
222 | @@ -284,6 +287,11 @@ | |||
223 | 284 | } | 287 | } |
224 | 285 | // finally compare | 288 | // finally compare |
225 | 286 | conf := cli.deriveSessionConfig(info) | 289 | conf := cli.deriveSessionConfig(info) |
226 | 290 | // compare authGetter by string | ||
227 | 291 | c.Check(fmt.Sprintf("%v", conf.AuthGetter), Equals, fmt.Sprintf("%v", cli.getAuthorization)) | ||
228 | 292 | // and set it to nil | ||
229 | 293 | conf.AuthGetter = nil | ||
230 | 294 | expected.AuthGetter = nil | ||
231 | 287 | c.Check(conf, DeepEquals, expected) | 295 | c.Check(conf, DeepEquals, expected) |
232 | 288 | } | 296 | } |
233 | 289 | 297 | ||
234 | @@ -292,15 +300,23 @@ | |||
235 | 292 | ******************************************************************/ | 300 | ******************************************************************/ |
236 | 293 | 301 | ||
237 | 294 | func (cs *clientSuite) TestStartServiceWorks(c *C) { | 302 | func (cs *clientSuite) TestStartServiceWorks(c *C) { |
238 | 303 | cs.writeTestConfig(map[string]interface{}{ | ||
239 | 304 | "auth_helper": "../scripts/dummyauth.sh", | ||
240 | 305 | }) | ||
241 | 295 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | 306 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
242 | 307 | cli.configure() | ||
243 | 296 | cli.log = cs.log | 308 | cli.log = cs.log |
246 | 297 | cli.serviceEndpoint = testibus.NewTestingEndpoint(condition.Work(true), nil) | 309 | cli.pushServiceEndpoint = testibus.NewTestingEndpoint(condition.Work(true), nil) |
247 | 298 | c.Check(cli.service, IsNil) | 310 | cli.postalServiceEndpoint = testibus.NewTestingEndpoint(condition.Work(true), nil) |
248 | 311 | c.Check(cli.pushService, IsNil) | ||
249 | 299 | c.Check(cli.startService(), IsNil) | 312 | c.Check(cli.startService(), IsNil) |
254 | 300 | c.Assert(cli.service, NotNil) | 313 | c.Assert(cli.pushService, NotNil) |
255 | 301 | c.Check(cli.service.IsRunning(), Equals, true) | 314 | c.Check(cli.pushService.IsRunning(), Equals, true) |
256 | 302 | c.Check(cli.service.GetMessageHandler(), NotNil) | 315 | c.Check(cli.postalService.IsRunning(), Equals, true) |
257 | 303 | cli.service.Stop() | 316 | c.Check(cli.postalService.GetMessageHandler(), NotNil) |
258 | 317 | c.Check(cli.pushService.GetRegistrationAuthorization(), Equals, "hello reg://") | ||
259 | 318 | cli.pushService.Stop() | ||
260 | 319 | cli.postalService.Stop() | ||
261 | 304 | } | 320 | } |
262 | 305 | 321 | ||
263 | 306 | func (cs *clientSuite) TestStartServiceErrorsOnNilLog(c *C) { | 322 | func (cs *clientSuite) TestStartServiceErrorsOnNilLog(c *C) { |
264 | @@ -312,7 +328,8 @@ | |||
265 | 312 | func (cs *clientSuite) TestStartServiceErrorsOnBusDialFail(c *C) { | 328 | func (cs *clientSuite) TestStartServiceErrorsOnBusDialFail(c *C) { |
266 | 313 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | 329 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
267 | 314 | cli.log = cs.log | 330 | cli.log = cs.log |
269 | 315 | cli.serviceEndpoint = testibus.NewTestingEndpoint(condition.Work(false), nil) | 331 | cli.pushServiceEndpoint = testibus.NewTestingEndpoint(condition.Work(false), nil) |
270 | 332 | cli.postalServiceEndpoint = testibus.NewTestingEndpoint(condition.Work(false), nil) | ||
271 | 316 | c.Check(cli.startService(), NotNil) | 333 | c.Check(cli.startService(), NotNil) |
272 | 317 | } | 334 | } |
273 | 318 | 335 | ||
274 | @@ -647,14 +664,16 @@ | |||
275 | 647 | func (cs *clientSuite) TestHandleUcastNotification(c *C) { | 664 | func (cs *clientSuite) TestHandleUcastNotification(c *C) { |
276 | 648 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | 665 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
277 | 649 | svcEndp := testibus.NewTestingEndpoint(condition.Work(true), condition.Work(true), uint32(1)) | 666 | svcEndp := testibus.NewTestingEndpoint(condition.Work(true), condition.Work(true), uint32(1)) |
278 | 667 | postEndp := testibus.NewTestingEndpoint(condition.Work(true), condition.Work(true), uint32(1)) | ||
279 | 650 | cli.log = cs.log | 668 | cli.log = cs.log |
281 | 651 | cli.serviceEndpoint = svcEndp | 669 | cli.pushServiceEndpoint = svcEndp |
282 | 670 | cli.postalServiceEndpoint = postEndp | ||
283 | 652 | notsEndp := testibus.NewTestingEndpoint(nil, condition.Work(true), uint32(1)) | 671 | notsEndp := testibus.NewTestingEndpoint(nil, condition.Work(true), uint32(1)) |
284 | 653 | cli.notificationsEndp = notsEndp | 672 | cli.notificationsEndp = notsEndp |
285 | 654 | c.Assert(cli.startService(), IsNil) | 673 | c.Assert(cli.startService(), IsNil) |
286 | 655 | c.Check(cli.handleUnicastNotification(notif), IsNil) | 674 | c.Check(cli.handleUnicastNotification(notif), IsNil) |
287 | 656 | // check we sent the notification | 675 | // check we sent the notification |
289 | 657 | args := testibus.GetCallArgs(svcEndp) | 676 | args := testibus.GetCallArgs(postEndp) |
290 | 658 | c.Assert(len(args), Not(Equals), 0) | 677 | c.Assert(len(args), Not(Equals), 0) |
291 | 659 | c.Check(args[len(args)-1].Member, Equals, "::Signal") | 678 | c.Check(args[len(args)-1].Member, Equals, "::Signal") |
292 | 660 | c.Check(cs.log.Captured(), Matches, `(?m).*sending notification "42" for "hello".*`) | 679 | c.Check(cs.log.Captured(), Matches, `(?m).*sending notification "42" for "hello".*`) |
293 | @@ -879,7 +898,7 @@ | |||
294 | 879 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | 898 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
295 | 880 | // before start, everything sucks: | 899 | // before start, everything sucks: |
296 | 881 | // no service, | 900 | // no service, |
298 | 882 | c.Check(cli.service, IsNil) | 901 | c.Check(cli.pushService, IsNil) |
299 | 883 | // no config, | 902 | // no config, |
300 | 884 | c.Check(string(cli.config.Addr), Equals, "") | 903 | c.Check(string(cli.config.Addr), Equals, "") |
301 | 885 | // no device id, | 904 | // no device id, |
302 | @@ -904,9 +923,10 @@ | |||
303 | 904 | // and a bus, | 923 | // and a bus, |
304 | 905 | c.Check(cli.notificationsEndp, NotNil) | 924 | c.Check(cli.notificationsEndp, NotNil) |
305 | 906 | // and a service, | 925 | // and a service, |
307 | 907 | c.Check(cli.service, NotNil) | 926 | c.Check(cli.pushService, NotNil) |
308 | 908 | // and everthying us just peachy! | 927 | // and everthying us just peachy! |
310 | 909 | cli.service.Stop() // cleanup | 928 | cli.pushService.Stop() // cleanup |
311 | 929 | cli.postalService.Stop() // cleanup | ||
312 | 910 | } | 930 | } |
313 | 911 | 931 | ||
314 | 912 | func (cs *clientSuite) TestStartCanFail(c *C) { | 932 | func (cs *clientSuite) TestStartCanFail(c *C) { |
315 | @@ -951,3 +971,33 @@ | |||
316 | 951 | c.Assert(err, NotNil) | 971 | c.Assert(err, NotNil) |
317 | 952 | c.Check(cs.log.Captured(), Matches, "(?msi).*showing notification: no way$") | 972 | c.Check(cs.log.Captured(), Matches, "(?msi).*showing notification: no way$") |
318 | 953 | } | 973 | } |
319 | 974 | |||
320 | 975 | /***************************************************************** | ||
321 | 976 | getAuthorization() tests | ||
322 | 977 | ******************************************************************/ | ||
323 | 978 | |||
324 | 979 | func (cs *clientSuite) TestGetAuthorizationIgnoresErrors(c *C) { | ||
325 | 980 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | ||
326 | 981 | cli.configure() | ||
327 | 982 | cli.config.AuthHelper = "/no/such/executable" | ||
328 | 983 | |||
329 | 984 | c.Check(cli.getAuthorization("xyzzy://"), Equals, "") | ||
330 | 985 | } | ||
331 | 986 | |||
332 | 987 | func (cs *clientSuite) TestGetAuthorizationGetsIt(c *C) { | ||
333 | 988 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | ||
334 | 989 | cli.configure() | ||
335 | 990 | cli.config.AuthHelper = "../scripts/dummyauth.sh" | ||
336 | 991 | |||
337 | 992 | c.Check(cli.getAuthorization("xyzzy://"), Equals, "hello xyzzy://") | ||
338 | 993 | } | ||
339 | 994 | |||
340 | 995 | func (cs *clientSuite) TestGetAuthorizationWorksIfUnsetOrNil(c *C) { | ||
341 | 996 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | ||
342 | 997 | cli.log = cs.log | ||
343 | 998 | |||
344 | 999 | c.Assert(cli.config, NotNil) | ||
345 | 1000 | c.Check(cli.getAuthorization("xyzzy://"), Equals, "") | ||
346 | 1001 | cli.configure() | ||
347 | 1002 | c.Check(cli.getAuthorization("xyzzy://"), Equals, "") | ||
348 | 1003 | } | ||
349 | 954 | 1004 | ||
350 | === added file 'client/service/common.go' | |||
351 | --- client/service/common.go 1970-01-01 00:00:00 +0000 | |||
352 | +++ client/service/common.go 2014-06-20 13:02:58 +0000 | |||
353 | @@ -0,0 +1,99 @@ | |||
354 | 1 | /* | ||
355 | 2 | Copyright 2014 Canonical Ltd. | ||
356 | 3 | |||
357 | 4 | This program is free software: you can redistribute it and/or modify it | ||
358 | 5 | under the terms of the GNU General Public License version 3, as published | ||
359 | 6 | by the Free Software Foundation. | ||
360 | 7 | |||
361 | 8 | This program is distributed in the hope that it will be useful, but | ||
362 | 9 | WITHOUT ANY WARRANTY; without even the implied warranties of | ||
363 | 10 | MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
364 | 11 | PURPOSE. See the GNU General Public License for more details. | ||
365 | 12 | |||
366 | 13 | You should have received a copy of the GNU General Public License along | ||
367 | 14 | with this program. If not, see <http://www.gnu.org/licenses/>. | ||
368 | 15 | */ | ||
369 | 16 | |||
370 | 17 | // package service implements the dbus-level service with which client | ||
371 | 18 | // applications are expected to interact. | ||
372 | 19 | package service | ||
373 | 20 | |||
374 | 21 | import ( | ||
375 | 22 | "errors" | ||
376 | 23 | "sync" | ||
377 | 24 | |||
378 | 25 | "launchpad.net/ubuntu-push/bus" | ||
379 | 26 | "launchpad.net/ubuntu-push/logger" | ||
380 | 27 | ) | ||
381 | 28 | |||
382 | 29 | type DBusService struct { | ||
383 | 30 | lock sync.RWMutex | ||
384 | 31 | state ServiceState | ||
385 | 32 | Log logger.Logger | ||
386 | 33 | Bus bus.Endpoint | ||
387 | 34 | } | ||
388 | 35 | |||
389 | 36 | // the service can be in a numnber of states | ||
390 | 37 | type ServiceState uint8 | ||
391 | 38 | |||
392 | 39 | const ( | ||
393 | 40 | StateUnknown ServiceState = iota | ||
394 | 41 | StateRunning // Start() has been successfully called | ||
395 | 42 | StateFinished // Stop() has been successfully called | ||
396 | 43 | ) | ||
397 | 44 | |||
398 | 45 | var ( | ||
399 | 46 | NotConfigured = errors.New("not configured") | ||
400 | 47 | AlreadyStarted = errors.New("already started") | ||
401 | 48 | BadArgCount = errors.New("Wrong number of arguments") | ||
402 | 49 | BadArgType = errors.New("Bad argument type") | ||
403 | 50 | ) | ||
404 | 51 | |||
405 | 52 | // IsRunning() returns whether the service's state is StateRunning | ||
406 | 53 | func (svc *DBusService) IsRunning() bool { | ||
407 | 54 | svc.lock.RLock() | ||
408 | 55 | defer svc.lock.RUnlock() | ||
409 | 56 | return svc.state == StateRunning | ||
410 | 57 | } | ||
411 | 58 | |||
412 | 59 | // Start() dials the bus, grab the name, and listens for method calls. | ||
413 | 60 | func (svc *DBusService) Start(dispatchMap bus.DispatchMap, busAddr bus.Address) error { | ||
414 | 61 | svc.lock.Lock() | ||
415 | 62 | defer svc.lock.Unlock() | ||
416 | 63 | if svc.state != StateUnknown { | ||
417 | 64 | return AlreadyStarted | ||
418 | 65 | } | ||
419 | 66 | if svc.Log == nil || svc.Bus == nil { | ||
420 | 67 | return NotConfigured | ||
421 | 68 | } | ||
422 | 69 | err := svc.Bus.Dial() | ||
423 | 70 | if err != nil { | ||
424 | 71 | return err | ||
425 | 72 | } | ||
426 | 73 | ch := svc.Bus.GrabName(true) | ||
427 | 74 | log := svc.Log | ||
428 | 75 | go func() { | ||
429 | 76 | for err := range ch { | ||
430 | 77 | if !svc.IsRunning() { | ||
431 | 78 | break | ||
432 | 79 | } | ||
433 | 80 | if err != nil { | ||
434 | 81 | log.Fatalf("name channel for %s got: %v", | ||
435 | 82 | busAddr.Name, err) | ||
436 | 83 | } | ||
437 | 84 | } | ||
438 | 85 | }() | ||
439 | 86 | svc.Bus.WatchMethod(dispatchMap, svc) | ||
440 | 87 | svc.state = StateRunning | ||
441 | 88 | return nil | ||
442 | 89 | } | ||
443 | 90 | |||
444 | 91 | // Stop() closes the bus and sets the state to StateFinished | ||
445 | 92 | func (svc *DBusService) Stop() { | ||
446 | 93 | svc.lock.Lock() | ||
447 | 94 | defer svc.lock.Unlock() | ||
448 | 95 | if svc.Bus != nil { | ||
449 | 96 | svc.Bus.Close() | ||
450 | 97 | } | ||
451 | 98 | svc.state = StateFinished | ||
452 | 99 | } | ||
453 | 0 | 100 | ||
454 | === added file 'client/service/postal.go' | |||
455 | --- client/service/postal.go 1970-01-01 00:00:00 +0000 | |||
456 | +++ client/service/postal.go 2014-06-20 13:02:58 +0000 | |||
457 | @@ -0,0 +1,122 @@ | |||
458 | 1 | /* | ||
459 | 2 | Copyright 2013-2014 Canonical Ltd. | ||
460 | 3 | |||
461 | 4 | This program is free software: you can redistribute it and/or modify it | ||
462 | 5 | under the terms of the GNU General Public License version 3, as published | ||
463 | 6 | by the Free Software Foundation. | ||
464 | 7 | |||
465 | 8 | This program is distributed in the hope that it will be useful, but | ||
466 | 9 | WITHOUT ANY WARRANTY; without even the implied warranties of | ||
467 | 10 | MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
468 | 11 | PURPOSE. See the GNU General Public License for more details. | ||
469 | 12 | |||
470 | 13 | You should have received a copy of the GNU General Public License along | ||
471 | 14 | with this program. If not, see <http://www.gnu.org/licenses/>. | ||
472 | 15 | */ | ||
473 | 16 | |||
474 | 17 | package service | ||
475 | 18 | |||
476 | 19 | import ( | ||
477 | 20 | "strings" | ||
478 | 21 | |||
479 | 22 | "launchpad.net/ubuntu-push/bus" | ||
480 | 23 | "launchpad.net/ubuntu-push/logger" | ||
481 | 24 | "launchpad.net/ubuntu-push/nih" | ||
482 | 25 | ) | ||
483 | 26 | |||
484 | 27 | // PostalService is the dbus api | ||
485 | 28 | type PostalService struct { | ||
486 | 29 | DBusService | ||
487 | 30 | mbox map[string][]string | ||
488 | 31 | msgHandler func([]byte) error | ||
489 | 32 | } | ||
490 | 33 | |||
491 | 34 | var ( | ||
492 | 35 | PostalServiceBusAddress = bus.Address{ | ||
493 | 36 | Interface: "com.ubuntu.Postal", | ||
494 | 37 | Path: "/com/ubuntu/Postal/*", | ||
495 | 38 | Name: "com.ubuntu.Postal", | ||
496 | 39 | } | ||
497 | 40 | ) | ||
498 | 41 | |||
499 | 42 | // NewPostalService() builds a new service and returns it. | ||
500 | 43 | func NewPostalService(bus bus.Endpoint, log logger.Logger) *PostalService { | ||
501 | 44 | var svc = &PostalService{} | ||
502 | 45 | svc.Log = log | ||
503 | 46 | svc.Bus = bus | ||
504 | 47 | return svc | ||
505 | 48 | } | ||
506 | 49 | |||
507 | 50 | // SetMessageHandler() sets the message-handling callback | ||
508 | 51 | func (svc *PostalService) SetMessageHandler(callback func([]byte) error) { | ||
509 | 52 | svc.lock.RLock() | ||
510 | 53 | defer svc.lock.RUnlock() | ||
511 | 54 | svc.msgHandler = callback | ||
512 | 55 | } | ||
513 | 56 | |||
514 | 57 | // GetMessageHandler() returns the (possibly nil) messaging handler callback | ||
515 | 58 | func (svc *PostalService) GetMessageHandler() func([]byte) error { | ||
516 | 59 | svc.lock.RLock() | ||
517 | 60 | defer svc.lock.RUnlock() | ||
518 | 61 | return svc.msgHandler | ||
519 | 62 | } | ||
520 | 63 | |||
521 | 64 | // Start() dials the bus, grab the name, and listens for method calls. | ||
522 | 65 | func (svc *PostalService) Start() error { | ||
523 | 66 | return svc.DBusService.Start(bus.DispatchMap{ | ||
524 | 67 | "Notifications": svc.notifications, | ||
525 | 68 | "Inject": svc.inject, | ||
526 | 69 | }, PostalServiceBusAddress) | ||
527 | 70 | } | ||
528 | 71 | |||
529 | 72 | func (svc *PostalService) notifications(path string, args, _ []interface{}) ([]interface{}, error) { | ||
530 | 73 | if len(args) != 0 { | ||
531 | 74 | return nil, BadArgCount | ||
532 | 75 | } | ||
533 | 76 | appname := string(nih.Unquote([]byte(path[strings.LastIndex(path, "/")+1:]))) | ||
534 | 77 | |||
535 | 78 | svc.lock.Lock() | ||
536 | 79 | defer svc.lock.Unlock() | ||
537 | 80 | |||
538 | 81 | if svc.mbox == nil { | ||
539 | 82 | return []interface{}{[]string(nil)}, nil | ||
540 | 83 | } | ||
541 | 84 | msgs := svc.mbox[appname] | ||
542 | 85 | delete(svc.mbox, appname) | ||
543 | 86 | |||
544 | 87 | return []interface{}{msgs}, nil | ||
545 | 88 | } | ||
546 | 89 | |||
547 | 90 | func (svc *PostalService) inject(path string, args, _ []interface{}) ([]interface{}, error) { | ||
548 | 91 | if len(args) != 1 { | ||
549 | 92 | return nil, BadArgCount | ||
550 | 93 | } | ||
551 | 94 | notif, ok := args[0].(string) | ||
552 | 95 | if !ok { | ||
553 | 96 | return nil, BadArgType | ||
554 | 97 | } | ||
555 | 98 | appname := string(nih.Unquote([]byte(path[strings.LastIndex(path, "/")+1:]))) | ||
556 | 99 | |||
557 | 100 | return nil, svc.Inject(appname, notif) | ||
558 | 101 | } | ||
559 | 102 | |||
560 | 103 | // Inject() signals to an application over dbus that a notification | ||
561 | 104 | // has arrived. | ||
562 | 105 | func (svc *PostalService) Inject(appname string, notif string) error { | ||
563 | 106 | svc.lock.Lock() | ||
564 | 107 | defer svc.lock.Unlock() | ||
565 | 108 | if svc.mbox == nil { | ||
566 | 109 | svc.mbox = make(map[string][]string) | ||
567 | 110 | } | ||
568 | 111 | svc.mbox[appname] = append(svc.mbox[appname], notif) | ||
569 | 112 | if svc.msgHandler != nil { | ||
570 | 113 | err := svc.msgHandler([]byte(notif)) | ||
571 | 114 | if err != nil { | ||
572 | 115 | svc.DBusService.Log.Errorf("msgHandler returned %v", err) | ||
573 | 116 | return err | ||
574 | 117 | } | ||
575 | 118 | svc.DBusService.Log.Debugf("call to msgHandler successful") | ||
576 | 119 | } | ||
577 | 120 | |||
578 | 121 | return svc.Bus.Signal("Notification", []interface{}{appname}) | ||
579 | 122 | } | ||
580 | 0 | 123 | ||
581 | === added file 'client/service/postal_test.go' | |||
582 | --- client/service/postal_test.go 1970-01-01 00:00:00 +0000 | |||
583 | +++ client/service/postal_test.go 2014-06-20 13:02:58 +0000 | |||
584 | @@ -0,0 +1,191 @@ | |||
585 | 1 | /* | ||
586 | 2 | Copyright 2014 Canonical Ltd. | ||
587 | 3 | |||
588 | 4 | This program is free software: you can redistribute it and/or modify it | ||
589 | 5 | under the terms of the GNU General Public License version 3, as published | ||
590 | 6 | by the Free Software Foundation. | ||
591 | 7 | |||
592 | 8 | This program is distributed in the hope that it will be useful, but | ||
593 | 9 | WITHOUT ANY WARRANTY; without even the implied warranties of | ||
594 | 10 | MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
595 | 11 | PURPOSE. See the GNU General Public License for more details. | ||
596 | 12 | |||
597 | 13 | You should have received a copy of the GNU General Public License along | ||
598 | 14 | with this program. If not, see <http://www.gnu.org/licenses/>. | ||
599 | 15 | */ | ||
600 | 16 | |||
601 | 17 | package service | ||
602 | 18 | |||
603 | 19 | import ( | ||
604 | 20 | "errors" | ||
605 | 21 | |||
606 | 22 | . "launchpad.net/gocheck" | ||
607 | 23 | |||
608 | 24 | "launchpad.net/ubuntu-push/bus" | ||
609 | 25 | testibus "launchpad.net/ubuntu-push/bus/testing" | ||
610 | 26 | "launchpad.net/ubuntu-push/logger" | ||
611 | 27 | helpers "launchpad.net/ubuntu-push/testing" | ||
612 | 28 | "launchpad.net/ubuntu-push/testing/condition" | ||
613 | 29 | ) | ||
614 | 30 | |||
615 | 31 | type postalSuite struct { | ||
616 | 32 | log logger.Logger | ||
617 | 33 | bus bus.Endpoint | ||
618 | 34 | } | ||
619 | 35 | |||
620 | 36 | var _ = Suite(&postalSuite{}) | ||
621 | 37 | |||
622 | 38 | func (ss *postalSuite) SetUpTest(c *C) { | ||
623 | 39 | ss.log = helpers.NewTestLogger(c, "debug") | ||
624 | 40 | ss.bus = testibus.NewTestingEndpoint(condition.Work(true), nil) | ||
625 | 41 | } | ||
626 | 42 | |||
627 | 43 | func (ss *postalSuite) TestStart(c *C) { | ||
628 | 44 | svc := NewPostalService(ss.bus, ss.log) | ||
629 | 45 | c.Check(svc.IsRunning(), Equals, false) | ||
630 | 46 | c.Check(svc.Start(), IsNil) | ||
631 | 47 | c.Check(svc.IsRunning(), Equals, true) | ||
632 | 48 | svc.Stop() | ||
633 | 49 | } | ||
634 | 50 | |||
635 | 51 | func (ss *postalSuite) TestStartTwice(c *C) { | ||
636 | 52 | svc := NewPostalService(ss.bus, ss.log) | ||
637 | 53 | c.Check(svc.Start(), IsNil) | ||
638 | 54 | c.Check(svc.Start(), Equals, AlreadyStarted) | ||
639 | 55 | svc.Stop() | ||
640 | 56 | } | ||
641 | 57 | |||
642 | 58 | func (ss *postalSuite) TestStartNoLog(c *C) { | ||
643 | 59 | svc := NewPostalService(ss.bus, nil) | ||
644 | 60 | c.Check(svc.Start(), Equals, NotConfigured) | ||
645 | 61 | } | ||
646 | 62 | |||
647 | 63 | func (ss *postalSuite) TestStartNoBus(c *C) { | ||
648 | 64 | svc := NewPostalService(nil, ss.log) | ||
649 | 65 | c.Check(svc.Start(), Equals, NotConfigured) | ||
650 | 66 | } | ||
651 | 67 | |||
652 | 68 | func (ss *postalSuite) TestStartFailsOnBusDialFailure(c *C) { | ||
653 | 69 | bus := testibus.NewTestingEndpoint(condition.Work(false), nil) | ||
654 | 70 | svc := NewPostalService(bus, ss.log) | ||
655 | 71 | c.Check(svc.Start(), ErrorMatches, `.*(?i)cond said no.*`) | ||
656 | 72 | svc.Stop() | ||
657 | 73 | } | ||
658 | 74 | |||
659 | 75 | func (ss *postalSuite) TestStartGrabsName(c *C) { | ||
660 | 76 | svc := NewPostalService(ss.bus, ss.log) | ||
661 | 77 | c.Assert(svc.Start(), IsNil) | ||
662 | 78 | callArgs := testibus.GetCallArgs(ss.bus) | ||
663 | 79 | defer svc.Stop() | ||
664 | 80 | c.Assert(callArgs, NotNil) | ||
665 | 81 | c.Check(callArgs[0].Member, Equals, "::GrabName") | ||
666 | 82 | } | ||
667 | 83 | |||
668 | 84 | func (ss *postalSuite) TestStopClosesBus(c *C) { | ||
669 | 85 | svc := NewPostalService(ss.bus, ss.log) | ||
670 | 86 | c.Assert(svc.Start(), IsNil) | ||
671 | 87 | svc.Stop() | ||
672 | 88 | callArgs := testibus.GetCallArgs(ss.bus) | ||
673 | 89 | c.Assert(callArgs, NotNil) | ||
674 | 90 | c.Check(callArgs[len(callArgs)-1].Member, Equals, "::Close") | ||
675 | 91 | } | ||
676 | 92 | |||
677 | 93 | // | ||
678 | 94 | // Injection tests | ||
679 | 95 | |||
680 | 96 | func (ss *postalSuite) TestInjectWorks(c *C) { | ||
681 | 97 | svc := NewPostalService(ss.bus, ss.log) | ||
682 | 98 | rvs, err := svc.inject("/hello", []interface{}{"world"}, nil) | ||
683 | 99 | c.Assert(err, IsNil) | ||
684 | 100 | c.Check(rvs, IsNil) | ||
685 | 101 | rvs, err = svc.inject("/hello", []interface{}{"there"}, nil) | ||
686 | 102 | c.Assert(err, IsNil) | ||
687 | 103 | c.Check(rvs, IsNil) | ||
688 | 104 | c.Assert(svc.mbox, HasLen, 1) | ||
689 | 105 | c.Assert(svc.mbox["hello"], HasLen, 2) | ||
690 | 106 | c.Check(svc.mbox["hello"][0], Equals, "world") | ||
691 | 107 | c.Check(svc.mbox["hello"][1], Equals, "there") | ||
692 | 108 | |||
693 | 109 | // and check it fired the right signal (twice) | ||
694 | 110 | callArgs := testibus.GetCallArgs(ss.bus) | ||
695 | 111 | c.Assert(callArgs, HasLen, 2) | ||
696 | 112 | c.Check(callArgs[0].Member, Equals, "::Signal") | ||
697 | 113 | c.Check(callArgs[0].Args, DeepEquals, []interface{}{"Notification", []interface{}{"hello"}}) | ||
698 | 114 | c.Check(callArgs[1], DeepEquals, callArgs[0]) | ||
699 | 115 | } | ||
700 | 116 | |||
701 | 117 | func (ss *postalSuite) TestInjectFailsIfInjectFails(c *C) { | ||
702 | 118 | bus := testibus.NewTestingEndpoint(condition.Work(true), | ||
703 | 119 | condition.Work(false)) | ||
704 | 120 | svc := NewPostalService(bus, ss.log) | ||
705 | 121 | svc.SetMessageHandler(func([]byte) error { return errors.New("fail") }) | ||
706 | 122 | _, err := svc.inject("/hello", []interface{}{"xyzzy"}, nil) | ||
707 | 123 | c.Check(err, NotNil) | ||
708 | 124 | } | ||
709 | 125 | |||
710 | 126 | func (ss *postalSuite) TestInjectFailsIfBadArgs(c *C) { | ||
711 | 127 | for i, s := range []struct { | ||
712 | 128 | args []interface{} | ||
713 | 129 | errt error | ||
714 | 130 | }{ | ||
715 | 131 | {nil, BadArgCount}, | ||
716 | 132 | {[]interface{}{}, BadArgCount}, | ||
717 | 133 | {[]interface{}{1}, BadArgType}, | ||
718 | 134 | {[]interface{}{1, 2}, BadArgCount}, | ||
719 | 135 | } { | ||
720 | 136 | reg, err := new(PostalService).inject("", s.args, nil) | ||
721 | 137 | c.Check(reg, IsNil, Commentf("iteration #%d", i)) | ||
722 | 138 | c.Check(err, Equals, s.errt, Commentf("iteration #%d", i)) | ||
723 | 139 | } | ||
724 | 140 | } | ||
725 | 141 | |||
726 | 142 | // | ||
727 | 143 | // Notifications tests | ||
728 | 144 | func (ss *postalSuite) TestNotificationsWorks(c *C) { | ||
729 | 145 | svc := NewPostalService(ss.bus, ss.log) | ||
730 | 146 | nots, err := svc.notifications("/hello", nil, nil) | ||
731 | 147 | c.Assert(err, IsNil) | ||
732 | 148 | c.Assert(nots, NotNil) | ||
733 | 149 | c.Assert(nots, HasLen, 1) | ||
734 | 150 | c.Check(nots[0], HasLen, 0) | ||
735 | 151 | if svc.mbox == nil { | ||
736 | 152 | svc.mbox = make(map[string][]string) | ||
737 | 153 | } | ||
738 | 154 | svc.mbox["hello"] = append(svc.mbox["hello"], "this", "thing") | ||
739 | 155 | nots, err = svc.notifications("/hello", nil, nil) | ||
740 | 156 | c.Assert(err, IsNil) | ||
741 | 157 | c.Assert(nots, NotNil) | ||
742 | 158 | c.Assert(nots, HasLen, 1) | ||
743 | 159 | c.Check(nots[0], DeepEquals, []string{"this", "thing"}) | ||
744 | 160 | } | ||
745 | 161 | |||
746 | 162 | func (ss *postalSuite) TestNotificationsFailsIfBadArgs(c *C) { | ||
747 | 163 | reg, err := new(PostalService).notifications("/foo", []interface{}{1}, nil) | ||
748 | 164 | c.Check(reg, IsNil) | ||
749 | 165 | c.Check(err, Equals, BadArgCount) | ||
750 | 166 | } | ||
751 | 167 | |||
752 | 168 | func (ss *postalSuite) TestMessageHandler(c *C) { | ||
753 | 169 | svc := new(PostalService) | ||
754 | 170 | c.Assert(svc.msgHandler, IsNil) | ||
755 | 171 | var ext = []byte{} | ||
756 | 172 | e := errors.New("Hello") | ||
757 | 173 | f := func(s []byte) error { ext = s; return e } | ||
758 | 174 | c.Check(svc.GetMessageHandler(), IsNil) | ||
759 | 175 | svc.SetMessageHandler(f) | ||
760 | 176 | c.Check(svc.GetMessageHandler(), NotNil) | ||
761 | 177 | c.Check(svc.msgHandler([]byte("37")), Equals, e) | ||
762 | 178 | c.Check(ext, DeepEquals, []byte("37")) | ||
763 | 179 | } | ||
764 | 180 | |||
765 | 181 | func (ss *postalSuite) TestInjectCallsMessageHandler(c *C) { | ||
766 | 182 | var ext = []byte{} | ||
767 | 183 | svc := NewPostalService(ss.bus, ss.log) | ||
768 | 184 | f := func(s []byte) error { ext = s; return nil } | ||
769 | 185 | svc.SetMessageHandler(f) | ||
770 | 186 | c.Check(svc.Inject("stuff", "{}"), IsNil) | ||
771 | 187 | c.Check(ext, DeepEquals, []byte("{}")) | ||
772 | 188 | err := errors.New("ouch") | ||
773 | 189 | svc.SetMessageHandler(func([]byte) error { return err }) | ||
774 | 190 | c.Check(svc.Inject("stuff", "{}"), Equals, err) | ||
775 | 191 | } | ||
776 | 0 | 192 | ||
777 | === modified file 'client/service/service.go' | |||
778 | --- client/service/service.go 2014-05-21 10:03:18 +0000 | |||
779 | +++ client/service/service.go 2014-06-20 13:02:58 +0000 | |||
780 | @@ -14,196 +14,84 @@ | |||
781 | 14 | with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | with this program. If not, see <http://www.gnu.org/licenses/>. |
782 | 15 | */ | 15 | */ |
783 | 16 | 16 | ||
784 | 17 | // package service implements the dbus-level service with which client | ||
785 | 18 | // applications are expected to interact. | ||
786 | 19 | package service | 17 | package service |
787 | 20 | 18 | ||
788 | 21 | import ( | 19 | import ( |
789 | 22 | "errors" | ||
790 | 23 | "os" | 20 | "os" |
792 | 24 | "sync" | 21 | "strings" |
793 | 25 | 22 | ||
794 | 26 | "launchpad.net/ubuntu-push/bus" | 23 | "launchpad.net/ubuntu-push/bus" |
795 | 27 | "launchpad.net/ubuntu-push/logger" | 24 | "launchpad.net/ubuntu-push/logger" |
796 | 25 | "launchpad.net/ubuntu-push/nih" | ||
797 | 28 | ) | 26 | ) |
798 | 29 | 27 | ||
807 | 30 | // Service is the dbus api | 28 | // PushService is the dbus api |
808 | 31 | type Service struct { | 29 | type PushService struct { |
809 | 32 | lock sync.RWMutex | 30 | DBusService |
810 | 33 | state ServiceState | 31 | regURL string |
811 | 34 | mbox map[string][]string | 32 | authGetter func(string) string |
804 | 35 | msgHandler func([]byte) error | ||
805 | 36 | Log logger.Logger | ||
806 | 37 | Bus bus.Endpoint | ||
812 | 38 | } | 33 | } |
813 | 39 | 34 | ||
814 | 40 | // the service can be in a numnber of states | ||
815 | 41 | type ServiceState uint8 | ||
816 | 42 | |||
817 | 43 | const ( | ||
818 | 44 | StateUnknown ServiceState = iota | ||
819 | 45 | StateRunning // Start() has been successfully called | ||
820 | 46 | StateFinished // Stop() has been successfully called | ||
821 | 47 | ) | ||
822 | 48 | |||
823 | 49 | var ( | 35 | var ( |
827 | 50 | NotConfigured = errors.New("not configured") | 36 | PushServiceBusAddress = bus.Address{ |
825 | 51 | AlreadyStarted = errors.New("already started") | ||
826 | 52 | BusAddress = bus.Address{ | ||
828 | 53 | Interface: "com.ubuntu.PushNotifications", | 37 | Interface: "com.ubuntu.PushNotifications", |
830 | 54 | Path: "/com/ubuntu/PushNotifications", | 38 | Path: "/com/ubuntu/PushNotifications/*", |
831 | 55 | Name: "com.ubuntu.PushNotifications", | 39 | Name: "com.ubuntu.PushNotifications", |
832 | 56 | } | 40 | } |
833 | 57 | ) | 41 | ) |
834 | 58 | 42 | ||
859 | 59 | // NewService() builds a new service and returns it. | 43 | // NewPushService() builds a new service and returns it. |
860 | 60 | func NewService(bus bus.Endpoint, log logger.Logger) *Service { | 44 | func NewPushService(bus bus.Endpoint, log logger.Logger) *PushService { |
861 | 61 | return &Service{Log: log, Bus: bus} | 45 | var svc = &PushService{} |
862 | 62 | } | 46 | svc.Log = log |
863 | 63 | 47 | svc.Bus = bus | |
864 | 64 | // SetMessageHandler() sets the message-handling callback | 48 | return svc |
865 | 65 | func (svc *Service) SetMessageHandler(callback func([]byte) error) { | 49 | } |
866 | 66 | svc.lock.Lock() | 50 | |
867 | 67 | defer svc.lock.Unlock() | 51 | // SetRegistrationURL() sets the registration url for the service |
868 | 68 | svc.msgHandler = callback | 52 | func (svc *PushService) SetRegistrationURL(url string) { |
869 | 69 | } | 53 | svc.lock.Lock() |
870 | 70 | 54 | defer svc.lock.Unlock() | |
871 | 71 | // GetMessageHandler() returns the (possibly nil) messaging handler callback | 55 | svc.regURL = url |
872 | 72 | func (svc *Service) GetMessageHandler() func([]byte) error { | 56 | } |
873 | 73 | svc.lock.RLock() | 57 | |
874 | 74 | defer svc.lock.RUnlock() | 58 | // SetAuthGetter() sets the authorization getter for the service |
875 | 75 | return svc.msgHandler | 59 | func (svc *PushService) SetAuthGetter(authGetter func(string) string) { |
876 | 76 | } | 60 | svc.lock.Lock() |
877 | 77 | 61 | defer svc.lock.Unlock() | |
878 | 78 | // IsRunning() returns whether the service's state is StateRunning | 62 | svc.authGetter = authGetter |
879 | 79 | func (svc *Service) IsRunning() bool { | 63 | } |
880 | 80 | svc.lock.RLock() | 64 | |
881 | 81 | defer svc.lock.RUnlock() | 65 | // GetRegistrationAuthorization() returns the authorization header for |
882 | 82 | return svc.state == StateRunning | 66 | // POSTing to the registration HTTP endpoint |
883 | 67 | func (svc *PushService) GetRegistrationAuthorization() string { | ||
884 | 68 | svc.lock.RLock() | ||
885 | 69 | defer svc.lock.RUnlock() | ||
886 | 70 | if svc.authGetter != nil && svc.regURL != "" { | ||
887 | 71 | return svc.authGetter(svc.regURL) | ||
888 | 72 | } else { | ||
889 | 73 | return "" | ||
890 | 74 | } | ||
891 | 83 | } | 75 | } |
892 | 84 | 76 | ||
893 | 85 | // Start() dials the bus, grab the name, and listens for method calls. | 77 | // Start() dials the bus, grab the name, and listens for method calls. |
946 | 86 | func (svc *Service) Start() error { | 78 | func (svc *PushService) Start() error { |
947 | 87 | svc.lock.Lock() | 79 | return svc.DBusService.Start(bus.DispatchMap{ |
948 | 88 | defer svc.lock.Unlock() | 80 | "Register": svc.register, |
949 | 89 | if svc.state != StateUnknown { | 81 | }, PushServiceBusAddress) |
950 | 90 | return AlreadyStarted | 82 | } |
951 | 91 | } | 83 | |
952 | 92 | if svc.Log == nil || svc.Bus == nil { | 84 | func (svc *PushService) register(path string, args, _ []interface{}) ([]interface{}, error) { |
953 | 93 | return NotConfigured | 85 | if len(args) != 0 { |
902 | 94 | } | ||
903 | 95 | err := svc.Bus.Dial() | ||
904 | 96 | if err != nil { | ||
905 | 97 | return err | ||
906 | 98 | } | ||
907 | 99 | ch := svc.Bus.GrabName(true) | ||
908 | 100 | log := svc.Log | ||
909 | 101 | go func() { | ||
910 | 102 | for err := range ch { | ||
911 | 103 | if !svc.IsRunning() { | ||
912 | 104 | break | ||
913 | 105 | } | ||
914 | 106 | if err != nil { | ||
915 | 107 | log.Fatalf("name channel for %s got: %v", | ||
916 | 108 | BusAddress.Name, err) | ||
917 | 109 | } | ||
918 | 110 | } | ||
919 | 111 | }() | ||
920 | 112 | svc.Bus.WatchMethod(bus.DispatchMap{ | ||
921 | 113 | "Register": svc.register, | ||
922 | 114 | "Notifications": svc.notifications, | ||
923 | 115 | "Inject": svc.inject, | ||
924 | 116 | }, svc) | ||
925 | 117 | svc.state = StateRunning | ||
926 | 118 | return nil | ||
927 | 119 | } | ||
928 | 120 | |||
929 | 121 | // Stop() closes the bus and sets the state to StateFinished | ||
930 | 122 | func (svc *Service) Stop() { | ||
931 | 123 | svc.lock.Lock() | ||
932 | 124 | defer svc.lock.Unlock() | ||
933 | 125 | if svc.Bus != nil { | ||
934 | 126 | svc.Bus.Close() | ||
935 | 127 | } | ||
936 | 128 | svc.state = StateFinished | ||
937 | 129 | } | ||
938 | 130 | |||
939 | 131 | var ( | ||
940 | 132 | BadArgCount = errors.New("Wrong number of arguments") | ||
941 | 133 | BadArgType = errors.New("Bad argument type") | ||
942 | 134 | ) | ||
943 | 135 | |||
944 | 136 | func (svc *Service) register(args []interface{}, _ []interface{}) ([]interface{}, error) { | ||
945 | 137 | if len(args) != 1 { | ||
954 | 138 | return nil, BadArgCount | 86 | return nil, BadArgCount |
955 | 139 | } | 87 | } |
960 | 140 | appname, ok := args[0].(string) | 88 | raw_appname := path[strings.LastIndex(path, "/")+1:] |
961 | 141 | if !ok { | 89 | appname := string(nih.Unquote([]byte(raw_appname))) |
958 | 142 | return nil, BadArgType | ||
959 | 143 | } | ||
962 | 144 | 90 | ||
964 | 145 | rv := os.Getenv("PUSH_REG_" + appname) | 91 | rv := os.Getenv("PUSH_REG_" + raw_appname) |
965 | 146 | if rv == "" { | 92 | if rv == "" { |
967 | 147 | rv = "this-is-an-opaque-block-of-random-bits-i-promise" | 93 | rv = appname + "::this-is-an-opaque-block-of-random-bits-i-promise" |
968 | 148 | } | 94 | } |
969 | 149 | 95 | ||
970 | 150 | return []interface{}{rv}, nil | 96 | return []interface{}{rv}, nil |
971 | 151 | } | 97 | } |
972 | 152 | |||
973 | 153 | func (svc *Service) notifications(args []interface{}, _ []interface{}) ([]interface{}, error) { | ||
974 | 154 | if len(args) != 1 { | ||
975 | 155 | return nil, BadArgCount | ||
976 | 156 | } | ||
977 | 157 | appname, ok := args[0].(string) | ||
978 | 158 | if !ok { | ||
979 | 159 | return nil, BadArgType | ||
980 | 160 | } | ||
981 | 161 | |||
982 | 162 | svc.lock.Lock() | ||
983 | 163 | defer svc.lock.Unlock() | ||
984 | 164 | |||
985 | 165 | if svc.mbox == nil { | ||
986 | 166 | return []interface{}{[]string(nil)}, nil | ||
987 | 167 | } | ||
988 | 168 | msgs := svc.mbox[appname] | ||
989 | 169 | delete(svc.mbox, appname) | ||
990 | 170 | |||
991 | 171 | return []interface{}{msgs}, nil | ||
992 | 172 | } | ||
993 | 173 | |||
994 | 174 | func (svc *Service) inject(args []interface{}, _ []interface{}) ([]interface{}, error) { | ||
995 | 175 | if len(args) != 2 { | ||
996 | 176 | return nil, BadArgCount | ||
997 | 177 | } | ||
998 | 178 | appname, ok := args[0].(string) | ||
999 | 179 | if !ok { | ||
1000 | 180 | return nil, BadArgType | ||
1001 | 181 | } | ||
1002 | 182 | notif, ok := args[1].(string) | ||
1003 | 183 | if !ok { | ||
1004 | 184 | return nil, BadArgType | ||
1005 | 185 | } | ||
1006 | 186 | |||
1007 | 187 | return nil, svc.Inject(appname, notif) | ||
1008 | 188 | } | ||
1009 | 189 | |||
1010 | 190 | // Inject() signals to an application over dbus that a notification | ||
1011 | 191 | // has arrived. | ||
1012 | 192 | func (svc *Service) Inject(appname string, notif string) error { | ||
1013 | 193 | svc.lock.Lock() | ||
1014 | 194 | defer svc.lock.Unlock() | ||
1015 | 195 | if svc.mbox == nil { | ||
1016 | 196 | svc.mbox = make(map[string][]string) | ||
1017 | 197 | } | ||
1018 | 198 | svc.mbox[appname] = append(svc.mbox[appname], notif) | ||
1019 | 199 | if svc.msgHandler != nil { | ||
1020 | 200 | err := svc.msgHandler([]byte(notif)) | ||
1021 | 201 | if err != nil { | ||
1022 | 202 | svc.Log.Errorf("msgHandler returned %v", err) | ||
1023 | 203 | return err | ||
1024 | 204 | } | ||
1025 | 205 | svc.Log.Debugf("call to msgHandler successful") | ||
1026 | 206 | } | ||
1027 | 207 | |||
1028 | 208 | return svc.Bus.Signal("Notification", []interface{}{appname}) | ||
1029 | 209 | } | ||
1030 | 210 | 98 | ||
1031 | === modified file 'client/service/service_test.go' | |||
1032 | --- client/service/service_test.go 2014-05-21 10:05:24 +0000 | |||
1033 | +++ client/service/service_test.go 2014-06-20 13:02:58 +0000 | |||
1034 | @@ -17,7 +17,7 @@ | |||
1035 | 17 | package service | 17 | package service |
1036 | 18 | 18 | ||
1037 | 19 | import ( | 19 | import ( |
1039 | 20 | "errors" | 20 | "fmt" |
1040 | 21 | "os" | 21 | "os" |
1041 | 22 | "testing" | 22 | "testing" |
1042 | 23 | 23 | ||
1043 | @@ -45,7 +45,7 @@ | |||
1044 | 45 | } | 45 | } |
1045 | 46 | 46 | ||
1046 | 47 | func (ss *serviceSuite) TestStart(c *C) { | 47 | func (ss *serviceSuite) TestStart(c *C) { |
1048 | 48 | svc := NewService(ss.bus, ss.log) | 48 | svc := NewPushService(ss.bus, ss.log) |
1049 | 49 | c.Check(svc.IsRunning(), Equals, false) | 49 | c.Check(svc.IsRunning(), Equals, false) |
1050 | 50 | c.Check(svc.Start(), IsNil) | 50 | c.Check(svc.Start(), IsNil) |
1051 | 51 | c.Check(svc.IsRunning(), Equals, true) | 51 | c.Check(svc.IsRunning(), Equals, true) |
1052 | @@ -53,31 +53,31 @@ | |||
1053 | 53 | } | 53 | } |
1054 | 54 | 54 | ||
1055 | 55 | func (ss *serviceSuite) TestStartTwice(c *C) { | 55 | func (ss *serviceSuite) TestStartTwice(c *C) { |
1057 | 56 | svc := NewService(ss.bus, ss.log) | 56 | svc := NewPushService(ss.bus, ss.log) |
1058 | 57 | c.Check(svc.Start(), IsNil) | 57 | c.Check(svc.Start(), IsNil) |
1059 | 58 | c.Check(svc.Start(), Equals, AlreadyStarted) | 58 | c.Check(svc.Start(), Equals, AlreadyStarted) |
1060 | 59 | svc.Stop() | 59 | svc.Stop() |
1061 | 60 | } | 60 | } |
1062 | 61 | 61 | ||
1063 | 62 | func (ss *serviceSuite) TestStartNoLog(c *C) { | 62 | func (ss *serviceSuite) TestStartNoLog(c *C) { |
1065 | 63 | svc := NewService(ss.bus, nil) | 63 | svc := NewPushService(ss.bus, nil) |
1066 | 64 | c.Check(svc.Start(), Equals, NotConfigured) | 64 | c.Check(svc.Start(), Equals, NotConfigured) |
1067 | 65 | } | 65 | } |
1068 | 66 | 66 | ||
1069 | 67 | func (ss *serviceSuite) TestStartNoBus(c *C) { | 67 | func (ss *serviceSuite) TestStartNoBus(c *C) { |
1071 | 68 | svc := NewService(nil, ss.log) | 68 | svc := NewPushService(nil, ss.log) |
1072 | 69 | c.Check(svc.Start(), Equals, NotConfigured) | 69 | c.Check(svc.Start(), Equals, NotConfigured) |
1073 | 70 | } | 70 | } |
1074 | 71 | 71 | ||
1075 | 72 | func (ss *serviceSuite) TestStartFailsOnBusDialFailure(c *C) { | 72 | func (ss *serviceSuite) TestStartFailsOnBusDialFailure(c *C) { |
1076 | 73 | bus := testibus.NewTestingEndpoint(condition.Work(false), nil) | 73 | bus := testibus.NewTestingEndpoint(condition.Work(false), nil) |
1078 | 74 | svc := NewService(bus, ss.log) | 74 | svc := NewPushService(bus, ss.log) |
1079 | 75 | c.Check(svc.Start(), ErrorMatches, `.*(?i)cond said no.*`) | 75 | c.Check(svc.Start(), ErrorMatches, `.*(?i)cond said no.*`) |
1080 | 76 | svc.Stop() | 76 | svc.Stop() |
1081 | 77 | } | 77 | } |
1082 | 78 | 78 | ||
1083 | 79 | func (ss *serviceSuite) TestStartGrabsName(c *C) { | 79 | func (ss *serviceSuite) TestStartGrabsName(c *C) { |
1085 | 80 | svc := NewService(ss.bus, ss.log) | 80 | svc := NewPushService(ss.bus, ss.log) |
1086 | 81 | c.Assert(svc.Start(), IsNil) | 81 | c.Assert(svc.Start(), IsNil) |
1087 | 82 | callArgs := testibus.GetCallArgs(ss.bus) | 82 | callArgs := testibus.GetCallArgs(ss.bus) |
1088 | 83 | defer svc.Stop() | 83 | defer svc.Stop() |
1089 | @@ -86,7 +86,7 @@ | |||
1090 | 86 | } | 86 | } |
1091 | 87 | 87 | ||
1092 | 88 | func (ss *serviceSuite) TestStopClosesBus(c *C) { | 88 | func (ss *serviceSuite) TestStopClosesBus(c *C) { |
1094 | 89 | svc := NewService(ss.bus, ss.log) | 89 | svc := NewPushService(ss.bus, ss.log) |
1095 | 90 | c.Assert(svc.Start(), IsNil) | 90 | c.Assert(svc.Start(), IsNil) |
1096 | 91 | svc.Stop() | 91 | svc.Stop() |
1097 | 92 | callArgs := testibus.GetCallArgs(ss.bus) | 92 | callArgs := testibus.GetCallArgs(ss.bus) |
1098 | @@ -96,24 +96,45 @@ | |||
1099 | 96 | 96 | ||
1100 | 97 | // registration tests | 97 | // registration tests |
1101 | 98 | 98 | ||
1102 | 99 | func (ss *serviceSuite) TestSetRegURLWorks(c *C) { | ||
1103 | 100 | svc := NewPushService(ss.bus, ss.log) | ||
1104 | 101 | c.Check(svc.regURL, Equals, "") | ||
1105 | 102 | svc.SetRegistrationURL("xyzzy://") | ||
1106 | 103 | c.Check(svc.regURL, Equals, "xyzzy://") | ||
1107 | 104 | } | ||
1108 | 105 | |||
1109 | 106 | func (ss *serviceSuite) TestSetAuthGetterWorks(c *C) { | ||
1110 | 107 | svc := NewPushService(ss.bus, ss.log) | ||
1111 | 108 | c.Check(svc.authGetter, IsNil) | ||
1112 | 109 | f := func(string) string { return "" } | ||
1113 | 110 | svc.SetAuthGetter(f) | ||
1114 | 111 | c.Check(fmt.Sprintf("%#v", svc.authGetter), Equals, fmt.Sprintf("%#v", f)) | ||
1115 | 112 | } | ||
1116 | 113 | |||
1117 | 114 | func (ss *serviceSuite) TestGetRegAuthWorks(c *C) { | ||
1118 | 115 | svc := NewPushService(ss.bus, ss.log) | ||
1119 | 116 | svc.SetRegistrationURL("xyzzy://") | ||
1120 | 117 | ch := make(chan string, 1) | ||
1121 | 118 | f := func(s string) string { ch <- s; return "Auth " + s } | ||
1122 | 119 | svc.SetAuthGetter(f) | ||
1123 | 120 | c.Check(svc.GetRegistrationAuthorization(), Equals, "Auth xyzzy://") | ||
1124 | 121 | c.Assert(len(ch), Equals, 1) | ||
1125 | 122 | c.Check(<-ch, Equals, "xyzzy://") | ||
1126 | 123 | } | ||
1127 | 124 | |||
1128 | 125 | func (ss *serviceSuite) TestGetRegAuthDoesNotPanic(c *C) { | ||
1129 | 126 | svc := NewPushService(ss.bus, ss.log) | ||
1130 | 127 | c.Check(svc.GetRegistrationAuthorization(), Equals, "") | ||
1131 | 128 | } | ||
1132 | 129 | |||
1133 | 99 | func (ss *serviceSuite) TestRegistrationFailsIfBadArgs(c *C) { | 130 | func (ss *serviceSuite) TestRegistrationFailsIfBadArgs(c *C) { |
1147 | 100 | for i, s := range []struct { | 131 | reg, err := new(PushService).register("", []interface{}{1}, nil) |
1148 | 101 | args []interface{} | 132 | c.Check(reg, IsNil) |
1149 | 102 | errt error | 133 | c.Check(err, Equals, BadArgCount) |
1137 | 103 | }{ | ||
1138 | 104 | {nil, BadArgCount}, // no args | ||
1139 | 105 | {[]interface{}{}, BadArgCount}, // still no args | ||
1140 | 106 | {[]interface{}{42}, BadArgType}, // bad arg type | ||
1141 | 107 | {[]interface{}{1, 2}, BadArgCount}, // too many args | ||
1142 | 108 | } { | ||
1143 | 109 | reg, err := new(Service).register(s.args, nil) | ||
1144 | 110 | c.Check(reg, IsNil, Commentf("iteration #%d", i)) | ||
1145 | 111 | c.Check(err, Equals, s.errt, Commentf("iteration #%d", i)) | ||
1146 | 112 | } | ||
1150 | 113 | } | 134 | } |
1151 | 114 | 135 | ||
1152 | 115 | func (ss *serviceSuite) TestRegistrationWorks(c *C) { | 136 | func (ss *serviceSuite) TestRegistrationWorks(c *C) { |
1154 | 116 | reg, err := new(Service).register([]interface{}{"this"}, nil) | 137 | reg, err := new(PushService).register("/this", nil, nil) |
1155 | 117 | c.Assert(reg, HasLen, 1) | 138 | c.Assert(reg, HasLen, 1) |
1156 | 118 | regs, ok := reg[0].(string) | 139 | regs, ok := reg[0].(string) |
1157 | 119 | c.Check(ok, Equals, true) | 140 | c.Check(ok, Equals, true) |
1158 | @@ -125,123 +146,10 @@ | |||
1159 | 125 | os.Setenv("PUSH_REG_stuff", "42") | 146 | os.Setenv("PUSH_REG_stuff", "42") |
1160 | 126 | defer os.Setenv("PUSH_REG_stuff", "") | 147 | defer os.Setenv("PUSH_REG_stuff", "") |
1161 | 127 | 148 | ||
1163 | 128 | reg, err := new(Service).register([]interface{}{"stuff"}, nil) | 149 | reg, err := new(PushService).register("/stuff", nil, nil) |
1164 | 129 | c.Assert(reg, HasLen, 1) | 150 | c.Assert(reg, HasLen, 1) |
1165 | 130 | regs, ok := reg[0].(string) | 151 | regs, ok := reg[0].(string) |
1166 | 131 | c.Check(ok, Equals, true) | 152 | c.Check(ok, Equals, true) |
1167 | 132 | c.Check(regs, Equals, "42") | 153 | c.Check(regs, Equals, "42") |
1168 | 133 | c.Check(err, IsNil) | 154 | c.Check(err, IsNil) |
1169 | 134 | } | 155 | } |
1170 | 135 | |||
1171 | 136 | // | ||
1172 | 137 | // Injection tests | ||
1173 | 138 | |||
1174 | 139 | func (ss *serviceSuite) TestInjectWorks(c *C) { | ||
1175 | 140 | svc := NewService(ss.bus, ss.log) | ||
1176 | 141 | rvs, err := svc.inject([]interface{}{"hello", "world"}, nil) | ||
1177 | 142 | c.Assert(err, IsNil) | ||
1178 | 143 | c.Check(rvs, IsNil) | ||
1179 | 144 | rvs, err = svc.inject([]interface{}{"hello", "there"}, nil) | ||
1180 | 145 | c.Assert(err, IsNil) | ||
1181 | 146 | c.Check(rvs, IsNil) | ||
1182 | 147 | c.Assert(svc.mbox, HasLen, 1) | ||
1183 | 148 | c.Assert(svc.mbox["hello"], HasLen, 2) | ||
1184 | 149 | c.Check(svc.mbox["hello"][0], Equals, "world") | ||
1185 | 150 | c.Check(svc.mbox["hello"][1], Equals, "there") | ||
1186 | 151 | |||
1187 | 152 | // and check it fired the right signal (twice) | ||
1188 | 153 | callArgs := testibus.GetCallArgs(ss.bus) | ||
1189 | 154 | c.Assert(callArgs, HasLen, 2) | ||
1190 | 155 | c.Check(callArgs[0].Member, Equals, "::Signal") | ||
1191 | 156 | c.Check(callArgs[0].Args, DeepEquals, []interface{}{"Notification", []interface{}{"hello"}}) | ||
1192 | 157 | c.Check(callArgs[1], DeepEquals, callArgs[0]) | ||
1193 | 158 | } | ||
1194 | 159 | |||
1195 | 160 | func (ss *serviceSuite) TestInjectFailsIfInjectFails(c *C) { | ||
1196 | 161 | bus := testibus.NewTestingEndpoint(condition.Work(true), | ||
1197 | 162 | condition.Work(false)) | ||
1198 | 163 | svc := NewService(bus, ss.log) | ||
1199 | 164 | svc.SetMessageHandler(func([]byte) error { return errors.New("fail") }) | ||
1200 | 165 | _, err := svc.inject([]interface{}{"hello", "xyzzy"}, nil) | ||
1201 | 166 | c.Check(err, NotNil) | ||
1202 | 167 | } | ||
1203 | 168 | |||
1204 | 169 | func (ss *serviceSuite) TestInjectFailsIfBadArgs(c *C) { | ||
1205 | 170 | for i, s := range []struct { | ||
1206 | 171 | args []interface{} | ||
1207 | 172 | errt error | ||
1208 | 173 | }{ | ||
1209 | 174 | {nil, BadArgCount}, | ||
1210 | 175 | {[]interface{}{}, BadArgCount}, | ||
1211 | 176 | {[]interface{}{1}, BadArgCount}, | ||
1212 | 177 | {[]interface{}{1, 2}, BadArgType}, | ||
1213 | 178 | {[]interface{}{"1", 2}, BadArgType}, | ||
1214 | 179 | {[]interface{}{1, "2"}, BadArgType}, | ||
1215 | 180 | {[]interface{}{1, 2, 3}, BadArgCount}, | ||
1216 | 181 | } { | ||
1217 | 182 | reg, err := new(Service).inject(s.args, nil) | ||
1218 | 183 | c.Check(reg, IsNil, Commentf("iteration #%d", i)) | ||
1219 | 184 | c.Check(err, Equals, s.errt, Commentf("iteration #%d", i)) | ||
1220 | 185 | } | ||
1221 | 186 | } | ||
1222 | 187 | |||
1223 | 188 | // | ||
1224 | 189 | // Notifications tests | ||
1225 | 190 | func (ss *serviceSuite) TestNotificationsWorks(c *C) { | ||
1226 | 191 | svc := NewService(ss.bus, ss.log) | ||
1227 | 192 | nots, err := svc.notifications([]interface{}{"hello"}, nil) | ||
1228 | 193 | c.Assert(err, IsNil) | ||
1229 | 194 | c.Assert(nots, NotNil) | ||
1230 | 195 | c.Assert(nots, HasLen, 1) | ||
1231 | 196 | c.Check(nots[0], HasLen, 0) | ||
1232 | 197 | if svc.mbox == nil { | ||
1233 | 198 | svc.mbox = make(map[string][]string) | ||
1234 | 199 | } | ||
1235 | 200 | svc.mbox["hello"] = append(svc.mbox["hello"], "this", "thing") | ||
1236 | 201 | nots, err = svc.notifications([]interface{}{"hello"}, nil) | ||
1237 | 202 | c.Assert(err, IsNil) | ||
1238 | 203 | c.Assert(nots, NotNil) | ||
1239 | 204 | c.Assert(nots, HasLen, 1) | ||
1240 | 205 | c.Check(nots[0], DeepEquals, []string{"this", "thing"}) | ||
1241 | 206 | } | ||
1242 | 207 | |||
1243 | 208 | func (ss *serviceSuite) TestNotificationsFailsIfBadArgs(c *C) { | ||
1244 | 209 | for i, s := range []struct { | ||
1245 | 210 | args []interface{} | ||
1246 | 211 | errt error | ||
1247 | 212 | }{ | ||
1248 | 213 | {nil, BadArgCount}, // no args | ||
1249 | 214 | {[]interface{}{}, BadArgCount}, // still no args | ||
1250 | 215 | {[]interface{}{42}, BadArgType}, // bad arg type | ||
1251 | 216 | {[]interface{}{1, 2}, BadArgCount}, // too many args | ||
1252 | 217 | } { | ||
1253 | 218 | reg, err := new(Service).notifications(s.args, nil) | ||
1254 | 219 | c.Check(reg, IsNil, Commentf("iteration #%d", i)) | ||
1255 | 220 | c.Check(err, Equals, s.errt, Commentf("iteration #%d", i)) | ||
1256 | 221 | } | ||
1257 | 222 | } | ||
1258 | 223 | |||
1259 | 224 | func (ss *serviceSuite) TestMessageHandler(c *C) { | ||
1260 | 225 | svc := new(Service) | ||
1261 | 226 | c.Assert(svc.msgHandler, IsNil) | ||
1262 | 227 | var ext = []byte{} | ||
1263 | 228 | e := errors.New("Hello") | ||
1264 | 229 | f := func(s []byte) error { ext = s; return e } | ||
1265 | 230 | c.Check(svc.GetMessageHandler(), IsNil) | ||
1266 | 231 | svc.SetMessageHandler(f) | ||
1267 | 232 | c.Check(svc.GetMessageHandler(), NotNil) | ||
1268 | 233 | c.Check(svc.msgHandler([]byte("37")), Equals, e) | ||
1269 | 234 | c.Check(ext, DeepEquals, []byte("37")) | ||
1270 | 235 | } | ||
1271 | 236 | |||
1272 | 237 | func (ss *serviceSuite) TestInjectCallsMessageHandler(c *C) { | ||
1273 | 238 | var ext = []byte{} | ||
1274 | 239 | svc := NewService(ss.bus, ss.log) | ||
1275 | 240 | f := func(s []byte) error { ext = s; return nil } | ||
1276 | 241 | svc.SetMessageHandler(f) | ||
1277 | 242 | c.Check(svc.Inject("stuff", "{}"), IsNil) | ||
1278 | 243 | c.Check(ext, DeepEquals, []byte("{}")) | ||
1279 | 244 | err := errors.New("ouch") | ||
1280 | 245 | svc.SetMessageHandler(func([]byte) error { return err }) | ||
1281 | 246 | c.Check(svc.Inject("stuff", "{}"), Equals, err) | ||
1282 | 247 | } | ||
1283 | 248 | 156 | ||
1284 | === modified file 'client/session/session.go' | |||
1285 | --- client/session/session.go 2014-05-23 05:59:38 +0000 | |||
1286 | +++ client/session/session.go 2014-06-20 13:02:58 +0000 | |||
1287 | @@ -26,7 +26,6 @@ | |||
1288 | 26 | "fmt" | 26 | "fmt" |
1289 | 27 | "math/rand" | 27 | "math/rand" |
1290 | 28 | "net" | 28 | "net" |
1291 | 29 | "os/exec" | ||
1292 | 30 | "strings" | 29 | "strings" |
1293 | 31 | "sync" | 30 | "sync" |
1294 | 32 | "sync/atomic" | 31 | "sync/atomic" |
1295 | @@ -87,7 +86,8 @@ | |||
1296 | 87 | ExpectAllRepairedTime time.Duration | 86 | ExpectAllRepairedTime time.Duration |
1297 | 88 | PEM []byte | 87 | PEM []byte |
1298 | 89 | Info map[string]interface{} | 88 | Info map[string]interface{} |
1300 | 90 | AuthHelper []string | 89 | AuthGetter func(string) string |
1301 | 90 | AuthURL string | ||
1302 | 91 | } | 91 | } |
1303 | 92 | 92 | ||
1304 | 93 | // ClientSession holds a client<->server session and its configuration. | 93 | // ClientSession holds a client<->server session and its configuration. |
1305 | @@ -244,21 +244,10 @@ | |||
1306 | 244 | // addAuthorization gets the authorization blob to send to the server | 244 | // addAuthorization gets the authorization blob to send to the server |
1307 | 245 | // and adds it to the session. | 245 | // and adds it to the session. |
1308 | 246 | func (sess *ClientSession) addAuthorization() error { | 246 | func (sess *ClientSession) addAuthorization() error { |
1324 | 247 | sess.Log.Debugf("adding authorization") | 247 | if sess.AuthGetter != nil { |
1325 | 248 | // using a helper, for now at least | 248 | sess.Log.Debugf("adding authorization") |
1326 | 249 | if len(sess.AuthHelper) == 0 { | 249 | sess.auth = sess.AuthGetter(sess.AuthURL) |
1327 | 250 | // do nothing if helper is unset or empty | 250 | } |
1313 | 251 | return nil | ||
1314 | 252 | } | ||
1315 | 253 | |||
1316 | 254 | auth, err := exec.Command(sess.AuthHelper[0], sess.AuthHelper[1:]...).Output() | ||
1317 | 255 | if err != nil { | ||
1318 | 256 | // For now we just log the error, as we don't want to block unauthorized users | ||
1319 | 257 | sess.Log.Errorf("unable to get the authorization token from the account: %v", err) | ||
1320 | 258 | } else { | ||
1321 | 259 | sess.auth = strings.TrimSpace(string(auth)) | ||
1322 | 260 | } | ||
1323 | 261 | |||
1328 | 262 | return nil | 251 | return nil |
1329 | 263 | } | 252 | } |
1330 | 264 | 253 | ||
1331 | 265 | 254 | ||
1332 | === modified file 'client/session/session_test.go' | |||
1333 | --- client/session/session_test.go 2014-05-23 05:59:38 +0000 | |||
1334 | +++ client/session/session_test.go 2014-06-20 13:02:58 +0000 | |||
1335 | @@ -353,34 +353,21 @@ | |||
1336 | 353 | ****************************************************************/ | 353 | ****************************************************************/ |
1337 | 354 | 354 | ||
1338 | 355 | func (cs *clientSessionSuite) TestAddAuthorizationAddsAuthorization(c *C) { | 355 | func (cs *clientSessionSuite) TestAddAuthorizationAddsAuthorization(c *C) { |
1367 | 356 | sess := &ClientSession{Log: cs.log} | 356 | url := "xyzzy://" |
1368 | 357 | sess.AuthHelper = []string{"echo", "some auth"} | 357 | sess := &ClientSession{Log: cs.log} |
1369 | 358 | c.Assert(sess.auth, Equals, "") | 358 | sess.AuthGetter = func(url string) string { return url + " auth'ed" } |
1370 | 359 | err := sess.addAuthorization() | 359 | sess.AuthURL = url |
1371 | 360 | c.Assert(err, IsNil) | 360 | c.Assert(sess.auth, Equals, "") |
1372 | 361 | c.Check(sess.auth, Equals, "some auth") | 361 | err := sess.addAuthorization() |
1373 | 362 | } | 362 | c.Assert(err, IsNil) |
1374 | 363 | 363 | c.Check(sess.auth, Equals, "xyzzy:// auth'ed") | |
1375 | 364 | func (cs *clientSessionSuite) TestAddAuthorizationIgnoresErrors(c *C) { | 364 | } |
1376 | 365 | sess := &ClientSession{Log: cs.log} | 365 | |
1377 | 366 | sess.AuthHelper = []string{"sh", "-c", "echo hello; false"} | 366 | func (cs *clientSessionSuite) TestAddAuthorizationSkipsIfUnset(c *C) { |
1378 | 367 | 367 | sess := &ClientSession{Log: cs.log} | |
1379 | 368 | c.Assert(sess.auth, Equals, "") | 368 | sess.AuthGetter = nil |
1380 | 369 | err := sess.addAuthorization() | 369 | c.Assert(sess.auth, Equals, "") |
1381 | 370 | c.Assert(err, IsNil) | 370 | err := sess.addAuthorization() |
1354 | 371 | c.Check(sess.auth, Equals, "") | ||
1355 | 372 | } | ||
1356 | 373 | |||
1357 | 374 | func (cs *clientSessionSuite) TestAddAuthorizationSkipsIfUnsetOrNil(c *C) { | ||
1358 | 375 | sess := &ClientSession{Log: cs.log} | ||
1359 | 376 | sess.AuthHelper = nil | ||
1360 | 377 | c.Assert(sess.auth, Equals, "") | ||
1361 | 378 | err := sess.addAuthorization() | ||
1362 | 379 | c.Assert(err, IsNil) | ||
1363 | 380 | c.Check(sess.auth, Equals, "") | ||
1364 | 381 | |||
1365 | 382 | sess.AuthHelper = []string{} | ||
1366 | 383 | err = sess.addAuthorization() | ||
1382 | 384 | c.Assert(err, IsNil) | 371 | c.Assert(err, IsNil) |
1383 | 385 | c.Check(sess.auth, Equals, "") | 372 | c.Check(sess.auth, Equals, "") |
1384 | 386 | } | 373 | } |
1385 | 387 | 374 | ||
1386 | === modified file 'debian/changelog' | |||
1387 | --- debian/changelog 2014-06-05 09:42:22 +0000 | |||
1388 | +++ debian/changelog 2014-06-20 13:02:58 +0000 | |||
1389 | @@ -1,3 +1,28 @@ | |||
1390 | 1 | ubuntu-push (0.31ubuntu1) UNRELEASED; urgency=medium | ||
1391 | 2 | |||
1392 | 3 | [ Samuele Pedroni ] | ||
1393 | 4 | * Support registering tokens and sending notifications with a token | ||
1394 | 5 | * Register script and scripts unicast support | ||
1395 | 6 | |||
1396 | 7 | [ Roberto Alsina ] | ||
1397 | 8 | * Make signing-helper generate a HTTP header instead of a querystring, | ||
1398 | 9 | and take a URL to sign. | ||
1399 | 10 | |||
1400 | 11 | [ John R. Lenton ] | ||
1401 | 12 | * Switch dbus api to retrieve app name from dbus path. | ||
1402 | 13 | * Move signing bits up from session to client, for reuse by service. | ||
1403 | 14 | * Change AuthHelper to be a string; auth helper should now expect a | ||
1404 | 15 | parameter (the url to sign). Added SessionURL to config. | ||
1405 | 16 | * Adapt our whoopsie wrapper to whoopsie's now more correct behavior wrt | ||
1406 | 17 | failing to get a mac address. | ||
1407 | 18 | * Add registration_url to config; hook up auth bits and reg url to | ||
1408 | 19 | client & service. | ||
1409 | 20 | |||
1410 | 21 | [ Guillermo Gonzalez ] | ||
1411 | 22 | * Split DBus service into PushService and PostalService | ||
1412 | 23 | |||
1413 | 24 | -- John R. Lenton <john.lenton@canonical.com> Fri, 06 Jun 2014 12:02:56 +0100 | ||
1414 | 25 | |||
1415 | 1 | ubuntu-push (0.3+14.10.20140605-0ubuntu1) utopic; urgency=medium | 26 | ubuntu-push (0.3+14.10.20140605-0ubuntu1) utopic; urgency=medium |
1416 | 2 | 27 | ||
1417 | 3 | [ John Lenton ] | 28 | [ John Lenton ] |
1418 | 4 | 29 | ||
1419 | === modified file 'debian/config.json' | |||
1420 | --- debian/config.json 2014-06-04 12:18:42 +0000 | |||
1421 | +++ debian/config.json 2014-06-20 13:02:58 +0000 | |||
1422 | @@ -1,5 +1,7 @@ | |||
1423 | 1 | { | 1 | { |
1425 | 2 | "auth_helper": [], | 2 | "auth_helper": "/usr/lib/ubuntu-push-client/signing-helper", |
1426 | 3 | "session_url": "https://push.ubuntu.com/", | ||
1427 | 4 | "registration_url": "https://push.ubuntu.com/registration", | ||
1428 | 3 | "connect_timeout": "20s", | 5 | "connect_timeout": "20s", |
1429 | 4 | "exchange_timeout": "30s", | 6 | "exchange_timeout": "30s", |
1430 | 5 | "hosts_cache_expiry": "12h", | 7 | "hosts_cache_expiry": "12h", |
1431 | 6 | 8 | ||
1432 | === modified file 'debian/rules' | |||
1433 | --- debian/rules 2014-05-02 12:42:27 +0000 | |||
1434 | +++ debian/rules 2014-06-20 13:02:58 +0000 | |||
1435 | @@ -5,7 +5,6 @@ | |||
1436 | 5 | export UBUNTU_PUSH_TEST_RESOURCES_ROOT := $(CURDIR) | 5 | export UBUNTU_PUSH_TEST_RESOURCES_ROOT := $(CURDIR) |
1437 | 6 | 6 | ||
1438 | 7 | override_dh_auto_build: | 7 | override_dh_auto_build: |
1439 | 8 | cd $$( find ./ -type d -regex '\./[^/]*/src/launchpad.net' -printf "%h\n" | head -n1) | ||
1440 | 9 | dh_auto_build --buildsystem=golang | 8 | dh_auto_build --buildsystem=golang |
1441 | 10 | (cd signing-helper && cmake . && make) | 9 | (cd signing-helper && cmake . && make) |
1442 | 11 | 10 | ||
1443 | 12 | 11 | ||
1444 | === modified file 'http13client/Makefile' | |||
1445 | --- http13client/Makefile 2014-03-20 12:15:36 +0000 | |||
1446 | +++ http13client/Makefile 2014-06-20 13:02:58 +0000 | |||
1447 | @@ -20,7 +20,8 @@ | |||
1448 | 20 | 20 | ||
1449 | 21 | prune: | 21 | prune: |
1450 | 22 | rm -rf example_test.go filetransport*.go fs*.go race.go range_test.go \ | 22 | rm -rf example_test.go filetransport*.go fs*.go race.go range_test.go \ |
1452 | 23 | sniff*.go httptest httputil testdata triv.go jar.go status.go | 23 | sniff*.go httptest httputil testdata triv.go jar.go status.go \ |
1453 | 24 | cookie_test.go | ||
1454 | 24 | sed -i -e 's+"launchpad.net/ubuntu-push/http13client/+"net/http/+' *.go | 25 | sed -i -e 's+"launchpad.net/ubuntu-push/http13client/+"net/http/+' *.go |
1455 | 25 | 26 | ||
1456 | 26 | fix: | 27 | fix: |
1457 | 27 | 28 | ||
1458 | === modified file 'http13client/_patches/empty_server.patch' | |||
1459 | --- http13client/_patches/empty_server.patch 2014-03-19 23:13:58 +0000 | |||
1460 | +++ http13client/_patches/empty_server.patch 2014-06-20 13:02:58 +0000 | |||
1461 | @@ -1,6 +1,6 @@ | |||
1462 | 1 | === modified file 'http13client/serve_test.go' | 1 | === modified file 'http13client/serve_test.go' |
1465 | 2 | --- http13client/serve_test.go 2014-03-19 21:38:56 +0000 | 2 | --- http13client/serve_test.go 2014-06-20 11:00:47 +0000 |
1466 | 3 | +++ http13client/serve_test.go 2014-03-19 22:27:37 +0000 | 3 | +++ http13client/serve_test.go 2014-06-20 12:00:22 +0000 |
1467 | 4 | @@ -2,60 +2,15 @@ | 4 | @@ -2,60 +2,15 @@ |
1468 | 5 | // Use of this source code is governed by a BSD-style | 5 | // Use of this source code is governed by a BSD-style |
1469 | 6 | // license that can be found in the LICENSE file. | 6 | // license that can be found in the LICENSE file. |
1470 | @@ -62,7 +62,7 @@ | |||
1471 | 62 | 62 | ||
1472 | 63 | func (a dummyAddr) Network() string { | 63 | func (a dummyAddr) Network() string { |
1473 | 64 | return string(a) | 64 | return string(a) |
1475 | 65 | @@ -93,1289 +48,6 @@ | 65 | @@ -93,1325 +48,6 @@ |
1476 | 66 | return nil | 66 | return nil |
1477 | 67 | } | 67 | } |
1478 | 68 | 68 | ||
1479 | @@ -906,31 +906,50 @@ | |||
1480 | 906 | -} | 906 | -} |
1481 | 907 | - | 907 | - |
1482 | 908 | -type serverExpectTest struct { | 908 | -type serverExpectTest struct { |
1484 | 909 | - contentLength int // of request body | 909 | - contentLength int // of request body |
1485 | 910 | - chunked bool | ||
1486 | 910 | - expectation string // e.g. "100-continue" | 911 | - expectation string // e.g. "100-continue" |
1487 | 911 | - readBody bool // whether handler should read the body (if false, sends StatusUnauthorized) | 912 | - readBody bool // whether handler should read the body (if false, sends StatusUnauthorized) |
1488 | 912 | - expectedResponse string // expected substring in first line of http response | 913 | - expectedResponse string // expected substring in first line of http response |
1489 | 913 | -} | 914 | -} |
1490 | 914 | - | 915 | - |
1491 | 916 | -func expectTest(contentLength int, expectation string, readBody bool, expectedResponse string) serverExpectTest { | ||
1492 | 917 | - return serverExpectTest{ | ||
1493 | 918 | - contentLength: contentLength, | ||
1494 | 919 | - expectation: expectation, | ||
1495 | 920 | - readBody: readBody, | ||
1496 | 921 | - expectedResponse: expectedResponse, | ||
1497 | 922 | - } | ||
1498 | 923 | -} | ||
1499 | 924 | - | ||
1500 | 915 | -var serverExpectTests = []serverExpectTest{ | 925 | -var serverExpectTests = []serverExpectTest{ |
1501 | 916 | - // Normal 100-continues, case-insensitive. | 926 | - // Normal 100-continues, case-insensitive. |
1504 | 917 | - {100, "100-continue", true, "100 Continue"}, | 927 | - expectTest(100, "100-continue", true, "100 Continue"), |
1505 | 918 | - {100, "100-cOntInUE", true, "100 Continue"}, | 928 | - expectTest(100, "100-cOntInUE", true, "100 Continue"), |
1506 | 919 | - | 929 | - |
1507 | 920 | - // No 100-continue. | 930 | - // No 100-continue. |
1509 | 921 | - {100, "", true, "200 OK"}, | 931 | - expectTest(100, "", true, "200 OK"), |
1510 | 922 | - | 932 | - |
1511 | 923 | - // 100-continue but requesting client to deny us, | 933 | - // 100-continue but requesting client to deny us, |
1512 | 924 | - // so it never reads the body. | 934 | - // so it never reads the body. |
1514 | 925 | - {100, "100-continue", false, "401 Unauthorized"}, | 935 | - expectTest(100, "100-continue", false, "401 Unauthorized"), |
1515 | 926 | - // Likewise without 100-continue: | 936 | - // Likewise without 100-continue: |
1517 | 927 | - {100, "", false, "401 Unauthorized"}, | 937 | - expectTest(100, "", false, "401 Unauthorized"), |
1518 | 928 | - | 938 | - |
1519 | 929 | - // Non-standard expectations are failures | 939 | - // Non-standard expectations are failures |
1521 | 930 | - {0, "a-pony", false, "417 Expectation Failed"}, | 940 | - expectTest(0, "a-pony", false, "417 Expectation Failed"), |
1522 | 931 | - | 941 | - |
1525 | 932 | - // Expect-100 requested but no body | 942 | - // Expect-100 requested but no body (is apparently okay: Issue 7625) |
1526 | 933 | - {0, "100-continue", true, "400 Bad Request"}, | 943 | - expectTest(0, "100-continue", true, "200 OK"), |
1527 | 944 | - // Expect-100 requested but handler doesn't read the body | ||
1528 | 945 | - expectTest(0, "100-continue", false, "401 Unauthorized"), | ||
1529 | 946 | - // Expect-100 continue with no body, but a chunked body. | ||
1530 | 947 | - { | ||
1531 | 948 | - expectation: "100-continue", | ||
1532 | 949 | - readBody: true, | ||
1533 | 950 | - chunked: true, | ||
1534 | 951 | - expectedResponse: "100 Continue", | ||
1535 | 952 | - }, | ||
1536 | 934 | -} | 953 | -} |
1537 | 935 | - | 954 | - |
1538 | 936 | -// Tests that the server responds to the "Expect" request header | 955 | -// Tests that the server responds to the "Expect" request header |
1539 | @@ -959,21 +978,38 @@ | |||
1540 | 959 | - | 978 | - |
1541 | 960 | - // Only send the body immediately if we're acting like an HTTP client | 979 | - // Only send the body immediately if we're acting like an HTTP client |
1542 | 961 | - // that doesn't send 100-continue expectations. | 980 | - // that doesn't send 100-continue expectations. |
1544 | 962 | - writeBody := test.contentLength > 0 && strings.ToLower(test.expectation) != "100-continue" | 981 | - writeBody := test.contentLength != 0 && strings.ToLower(test.expectation) != "100-continue" |
1545 | 963 | - | 982 | - |
1546 | 964 | - go func() { | 983 | - go func() { |
1547 | 984 | - contentLen := fmt.Sprintf("Content-Length: %d", test.contentLength) | ||
1548 | 985 | - if test.chunked { | ||
1549 | 986 | - contentLen = "Transfer-Encoding: chunked" | ||
1550 | 987 | - } | ||
1551 | 965 | - _, err := fmt.Fprintf(conn, "POST /?readbody=%v HTTP/1.1\r\n"+ | 988 | - _, err := fmt.Fprintf(conn, "POST /?readbody=%v HTTP/1.1\r\n"+ |
1552 | 966 | - "Connection: close\r\n"+ | 989 | - "Connection: close\r\n"+ |
1554 | 967 | - "Content-Length: %d\r\n"+ | 990 | - "%s\r\n"+ |
1555 | 968 | - "Expect: %s\r\nHost: foo\r\n\r\n", | 991 | - "Expect: %s\r\nHost: foo\r\n\r\n", |
1557 | 969 | - test.readBody, test.contentLength, test.expectation) | 992 | - test.readBody, contentLen, test.expectation) |
1558 | 970 | - if err != nil { | 993 | - if err != nil { |
1559 | 971 | - t.Errorf("On test %#v, error writing request headers: %v", test, err) | 994 | - t.Errorf("On test %#v, error writing request headers: %v", test, err) |
1560 | 972 | - return | 995 | - return |
1561 | 973 | - } | 996 | - } |
1562 | 974 | - if writeBody { | 997 | - if writeBody { |
1563 | 998 | - var targ io.WriteCloser = struct { | ||
1564 | 999 | - io.Writer | ||
1565 | 1000 | - io.Closer | ||
1566 | 1001 | - }{ | ||
1567 | 1002 | - conn, | ||
1568 | 1003 | - ioutil.NopCloser(nil), | ||
1569 | 1004 | - } | ||
1570 | 1005 | - if test.chunked { | ||
1571 | 1006 | - targ = httputil.NewChunkedWriter(conn) | ||
1572 | 1007 | - } | ||
1573 | 975 | - body := strings.Repeat("A", test.contentLength) | 1008 | - body := strings.Repeat("A", test.contentLength) |
1575 | 976 | - _, err = fmt.Fprint(conn, body) | 1009 | - _, err = fmt.Fprint(targ, body) |
1576 | 1010 | - if err == nil { | ||
1577 | 1011 | - err = targ.Close() | ||
1578 | 1012 | - } | ||
1579 | 977 | - if err != nil { | 1013 | - if err != nil { |
1580 | 978 | - if !test.readBody { | 1014 | - if !test.readBody { |
1581 | 979 | - // Server likely already hung up on us. | 1015 | - // Server likely already hung up on us. |
1582 | @@ -1352,7 +1388,7 @@ | |||
1583 | 1352 | type neverEnding byte | 1388 | type neverEnding byte |
1584 | 1353 | 1389 | ||
1585 | 1354 | func (b neverEnding) Read(p []byte) (n int, err error) { | 1390 | func (b neverEnding) Read(p []byte) (n int, err error) { |
1587 | 1355 | @@ -1384,1344 +56,3 @@ | 1391 | @@ -1420,1392 +56,3 @@ |
1588 | 1356 | } | 1392 | } |
1589 | 1357 | return len(p), nil | 1393 | return len(p), nil |
1590 | 1358 | } | 1394 | } |
1591 | @@ -2080,7 +2116,7 @@ | |||
1592 | 2080 | - got := ht.rawResponse(req) | 2116 | - got := ht.rawResponse(req) |
1593 | 2081 | - wantStatus := fmt.Sprintf("%d %s", code, StatusText(code)) | 2117 | - wantStatus := fmt.Sprintf("%d %s", code, StatusText(code)) |
1594 | 2082 | - if !strings.Contains(got, wantStatus) { | 2118 | - if !strings.Contains(got, wantStatus) { |
1596 | 2083 | - t.Errorf("Code %d: Wanted %q Modified for %q: %s", code, req, got) | 2119 | - t.Errorf("Code %d: Wanted %q Modified for %q: %s", code, wantStatus, req, got) |
1597 | 2084 | - } else if strings.Contains(got, "Content-Length") { | 2120 | - } else if strings.Contains(got, "Content-Length") { |
1598 | 2085 | - t.Errorf("Code %d: Got a Content-Length from %q: %s", code, req, got) | 2121 | - t.Errorf("Code %d: Got a Content-Length from %q: %s", code, req, got) |
1599 | 2086 | - } else if strings.Contains(got, "stuff") { | 2122 | - } else if strings.Contains(got, "stuff") { |
1600 | @@ -2090,6 +2126,21 @@ | |||
1601 | 2090 | - } | 2126 | - } |
1602 | 2091 | -} | 2127 | -} |
1603 | 2092 | - | 2128 | - |
1604 | 2129 | -func TestContentTypeOkayOn204(t *testing.T) { | ||
1605 | 2130 | - ht := newHandlerTest(HandlerFunc(func(w ResponseWriter, r *Request) { | ||
1606 | 2131 | - w.Header().Set("Content-Length", "123") // suppressed | ||
1607 | 2132 | - w.Header().Set("Content-Type", "foo/bar") | ||
1608 | 2133 | - w.WriteHeader(204) | ||
1609 | 2134 | - })) | ||
1610 | 2135 | - got := ht.rawResponse("GET / HTTP/1.1") | ||
1611 | 2136 | - if !strings.Contains(got, "Content-Type: foo/bar") { | ||
1612 | 2137 | - t.Errorf("Response = %q; want Content-Type: foo/bar", got) | ||
1613 | 2138 | - } | ||
1614 | 2139 | - if strings.Contains(got, "Content-Length: 123") { | ||
1615 | 2140 | - t.Errorf("Response = %q; don't want a Content-Length", got) | ||
1616 | 2141 | - } | ||
1617 | 2142 | -} | ||
1618 | 2143 | - | ||
1619 | 2093 | -// Issue 6995 | 2144 | -// Issue 6995 |
1620 | 2094 | -// A server Handler can receive a Request, and then turn around and | 2145 | -// A server Handler can receive a Request, and then turn around and |
1621 | 2095 | -// give a copy of that Request.Body out to the Transport (e.g. any | 2146 | -// give a copy of that Request.Body out to the Transport (e.g. any |
1622 | @@ -2261,7 +2312,7 @@ | |||
1623 | 2261 | - ts.Config.ErrorLog = log.New(ioutil.Discard, "", 0) | 2312 | - ts.Config.ErrorLog = log.New(ioutil.Discard, "", 0) |
1624 | 2262 | - ts.Config.ConnState = func(c net.Conn, state ConnState) { | 2313 | - ts.Config.ConnState = func(c net.Conn, state ConnState) { |
1625 | 2263 | - if c == nil { | 2314 | - if c == nil { |
1627 | 2264 | - t.Error("nil conn seen in state %s", state) | 2315 | - t.Errorf("nil conn seen in state %s", state) |
1628 | 2265 | - return | 2316 | - return |
1629 | 2266 | - } | 2317 | - } |
1630 | 2267 | - mu.Lock() | 2318 | - mu.Lock() |
1631 | @@ -2397,6 +2448,39 @@ | |||
1632 | 2397 | - } | 2448 | - } |
1633 | 2398 | -} | 2449 | -} |
1634 | 2399 | - | 2450 | - |
1635 | 2451 | -// golang.org/issue/7856 | ||
1636 | 2452 | -func TestServerEmptyBodyRace(t *testing.T) { | ||
1637 | 2453 | - defer afterTest(t) | ||
1638 | 2454 | - var n int32 | ||
1639 | 2455 | - ts := httptest.NewServer(HandlerFunc(func(rw ResponseWriter, req *Request) { | ||
1640 | 2456 | - atomic.AddInt32(&n, 1) | ||
1641 | 2457 | - })) | ||
1642 | 2458 | - defer ts.Close() | ||
1643 | 2459 | - var wg sync.WaitGroup | ||
1644 | 2460 | - const reqs = 20 | ||
1645 | 2461 | - for i := 0; i < reqs; i++ { | ||
1646 | 2462 | - wg.Add(1) | ||
1647 | 2463 | - go func() { | ||
1648 | 2464 | - defer wg.Done() | ||
1649 | 2465 | - res, err := Get(ts.URL) | ||
1650 | 2466 | - if err != nil { | ||
1651 | 2467 | - t.Error(err) | ||
1652 | 2468 | - return | ||
1653 | 2469 | - } | ||
1654 | 2470 | - defer res.Body.Close() | ||
1655 | 2471 | - _, err = io.Copy(ioutil.Discard, res.Body) | ||
1656 | 2472 | - if err != nil { | ||
1657 | 2473 | - t.Error(err) | ||
1658 | 2474 | - return | ||
1659 | 2475 | - } | ||
1660 | 2476 | - }() | ||
1661 | 2477 | - } | ||
1662 | 2478 | - wg.Wait() | ||
1663 | 2479 | - if got := atomic.LoadInt32(&n); got != reqs { | ||
1664 | 2480 | - t.Errorf("handler ran %d times; want %d", got, reqs) | ||
1665 | 2481 | - } | ||
1666 | 2482 | -} | ||
1667 | 2483 | - | ||
1668 | 2400 | -func TestServerConnStateNew(t *testing.T) { | 2484 | -func TestServerConnStateNew(t *testing.T) { |
1669 | 2401 | - sawNew := false // if the test is buggy, we'll race on this variable. | 2485 | - sawNew := false // if the test is buggy, we'll race on this variable. |
1670 | 2402 | - srv := &Server{ | 2486 | - srv := &Server{ |
1671 | @@ -2699,9 +2783,9 @@ | |||
1672 | 2699 | -} | 2783 | -} |
1673 | 2700 | 2784 | ||
1674 | 2701 | === modified file 'http13client/server.go' | 2785 | === modified file 'http13client/server.go' |
1678 | 2702 | --- http13client/server.go 2014-03-19 20:20:19 +0000 | 2786 | --- http13client/server.go 2014-06-20 11:00:47 +0000 |
1679 | 2703 | +++ http13client/server.go 2014-03-19 22:27:37 +0000 | 2787 | +++ http13client/server.go 2014-06-20 12:05:53 +0000 |
1680 | 2704 | @@ -2,1984 +2,17 @@ | 2788 | @@ -2,1976 +2,16 @@ |
1681 | 2705 | // Use of this source code is governed by a BSD-style | 2789 | // Use of this source code is governed by a BSD-style |
1682 | 2706 | // license that can be found in the LICENSE file. | 2790 | // license that can be found in the LICENSE file. |
1683 | 2707 | 2791 | ||
1684 | @@ -2723,7 +2807,7 @@ | |||
1685 | 2723 | - "path" | 2807 | - "path" |
1686 | 2724 | - "runtime" | 2808 | - "runtime" |
1687 | 2725 | - "strconv" | 2809 | - "strconv" |
1689 | 2726 | "strings" | 2810 | - "strings" |
1690 | 2727 | "sync" | 2811 | "sync" |
1691 | 2728 | - "sync/atomic" | 2812 | - "sync/atomic" |
1692 | 2729 | - "time" | 2813 | - "time" |
1693 | @@ -3506,18 +3590,16 @@ | |||
1694 | 3506 | - } | 3590 | - } |
1695 | 3507 | - | 3591 | - |
1696 | 3508 | - code := w.status | 3592 | - code := w.status |
1704 | 3509 | - if !bodyAllowedForStatus(code) { | 3593 | - if bodyAllowedForStatus(code) { |
1698 | 3510 | - // Must not have body. | ||
1699 | 3511 | - // RFC 2616 section 10.3.5: "the response MUST NOT include other entity-headers" | ||
1700 | 3512 | - for _, k := range []string{"Content-Type", "Content-Length", "Transfer-Encoding"} { | ||
1701 | 3513 | - delHeader(k) | ||
1702 | 3514 | - } | ||
1703 | 3515 | - } else { | ||
1705 | 3516 | - // If no content type, apply sniffing algorithm to body. | 3594 | - // If no content type, apply sniffing algorithm to body. |
1706 | 3517 | - _, haveType := header["Content-Type"] | 3595 | - _, haveType := header["Content-Type"] |
1707 | 3518 | - if !haveType { | 3596 | - if !haveType { |
1708 | 3519 | - setHeader.contentType = DetectContentType(p) | 3597 | - setHeader.contentType = DetectContentType(p) |
1709 | 3520 | - } | 3598 | - } |
1710 | 3599 | - } else { | ||
1711 | 3600 | - for _, k := range suppressedHeaders(code) { | ||
1712 | 3601 | - delHeader(k) | ||
1713 | 3602 | - } | ||
1714 | 3521 | - } | 3603 | - } |
1715 | 3522 | - | 3604 | - |
1716 | 3523 | - if _, ok := header["Date"]; !ok { | 3605 | - if _, ok := header["Date"]; !ok { |
1717 | @@ -3865,16 +3947,10 @@ | |||
1718 | 3865 | - // Expect 100 Continue support | 3947 | - // Expect 100 Continue support |
1719 | 3866 | - req := w.req | 3948 | - req := w.req |
1720 | 3867 | - if req.expectsContinue() { | 3949 | - if req.expectsContinue() { |
1722 | 3868 | - if req.ProtoAtLeast(1, 1) { | 3950 | - if req.ProtoAtLeast(1, 1) && req.ContentLength != 0 { |
1723 | 3869 | - // Wrap the Body reader with one that replies on the connection | 3951 | - // Wrap the Body reader with one that replies on the connection |
1724 | 3870 | - req.Body = &expectContinueReader{readCloser: req.Body, resp: w} | 3952 | - req.Body = &expectContinueReader{readCloser: req.Body, resp: w} |
1725 | 3871 | - } | 3953 | - } |
1726 | 3872 | - if req.ContentLength == 0 { | ||
1727 | 3873 | - w.Header().Set("Connection", "close") | ||
1728 | 3874 | - w.WriteHeader(StatusBadRequest) | ||
1729 | 3875 | - w.finishRequest() | ||
1730 | 3876 | - break | ||
1731 | 3877 | - } | ||
1732 | 3878 | - req.Header.Del("Expect") | 3954 | - req.Header.Del("Expect") |
1733 | 3879 | - } else if req.Header.get("Expect") != "" { | 3955 | - } else if req.Header.get("Expect") != "" { |
1734 | 3880 | - w.sendExpectationFailed() | 3956 | - w.sendExpectationFailed() |
1735 | @@ -4685,11 +4761,11 @@ | |||
1736 | 4685 | -} | 4761 | -} |
1737 | 4686 | +) | 4762 | +) |
1738 | 4687 | 4763 | ||
1744 | 4688 | // eofReader is a non-nil io.ReadCloser that always returns EOF. | 4764 | type eofReaderWithWriteTo struct{} |
1745 | 4689 | // It embeds a *strings.Reader so it still has a WriteTo method | 4765 | |
1746 | 4690 | @@ -1992,28 +25,6 @@ | 4766 | @@ -1991,28 +31,6 @@ |
1747 | 4691 | ioutil.NopCloser(nil), | 4767 | // Verify that an io.Copy from an eofReader won't require a buffer. |
1748 | 4692 | } | 4768 | var _ io.WriterTo = eofReader |
1749 | 4693 | 4769 | ||
1750 | 4694 | -// initNPNRequest is an HTTP handler that initializes certain | 4770 | -// initNPNRequest is an HTTP handler that initializes certain |
1751 | 4695 | -// uninitialized fields in its *Request. Such partially-initialized | 4771 | -// uninitialized fields in its *Request. Such partially-initialized |
1752 | 4696 | 4772 | ||
1753 | === modified file 'http13client/_patches/fix_code.patch' | |||
1754 | --- http13client/_patches/fix_code.patch 2014-03-19 23:13:58 +0000 | |||
1755 | +++ http13client/_patches/fix_code.patch 2014-06-20 13:02:58 +0000 | |||
1756 | @@ -1,6 +1,6 @@ | |||
1757 | 1 | === modified file 'http13client/client.go' | 1 | === modified file 'http13client/client.go' |
1760 | 2 | --- http13client/client.go 2014-03-19 20:20:19 +0000 | 2 | --- http13client/client.go 2014-06-20 11:00:47 +0000 |
1761 | 3 | +++ http13client/client.go 2014-03-19 22:27:37 +0000 | 3 | +++ http13client/client.go 2014-06-20 12:05:53 +0000 |
1762 | 4 | @@ -17,6 +17,7 @@ | 4 | @@ -17,6 +17,7 @@ |
1763 | 5 | "io/ioutil" | 5 | "io/ioutil" |
1764 | 6 | "log" | 6 | "log" |
1765 | @@ -18,7 +18,7 @@ | |||
1766 | 18 | 18 | ||
1767 | 19 | // Timeout specifies a time limit for requests made by this | 19 | // Timeout specifies a time limit for requests made by this |
1768 | 20 | // Client. The timeout includes connection time, any | 20 | // Client. The timeout includes connection time, any |
1770 | 21 | @@ -177,7 +178,7 @@ | 21 | @@ -184,7 +185,7 @@ |
1771 | 22 | // Headers, leaving it uninitialized. We guarantee to the | 22 | // Headers, leaving it uninitialized. We guarantee to the |
1772 | 23 | // Transport that this has been initialized, though. | 23 | // Transport that this has been initialized, though. |
1773 | 24 | if req.Header == nil { | 24 | if req.Header == nil { |
1774 | @@ -27,7 +27,7 @@ | |||
1775 | 27 | } | 27 | } |
1776 | 28 | 28 | ||
1777 | 29 | if u := req.URL.User; u != nil { | 29 | if u := req.URL.User; u != nil { |
1779 | 30 | @@ -308,7 +309,7 @@ | 30 | @@ -316,7 +317,7 @@ |
1780 | 31 | if ireq.Method == "POST" || ireq.Method == "PUT" { | 31 | if ireq.Method == "POST" || ireq.Method == "PUT" { |
1781 | 32 | nreq.Method = "GET" | 32 | nreq.Method = "GET" |
1782 | 33 | } | 33 | } |
1783 | @@ -38,8 +38,8 @@ | |||
1784 | 38 | break | 38 | break |
1785 | 39 | 39 | ||
1786 | 40 | === modified file 'http13client/cookie.go' | 40 | === modified file 'http13client/cookie.go' |
1789 | 41 | --- http13client/cookie.go 2014-03-19 20:20:19 +0000 | 41 | --- http13client/cookie.go 2014-06-20 11:00:47 +0000 |
1790 | 42 | +++ http13client/cookie.go 2014-03-19 22:27:37 +0000 | 42 | +++ http13client/cookie.go 2014-06-20 12:05:53 +0000 |
1791 | 43 | @@ -5,10 +5,9 @@ | 43 | @@ -5,10 +5,9 @@ |
1792 | 44 | package http | 44 | package http |
1793 | 45 | 45 | ||
1794 | @@ -94,7 +94,7 @@ | |||
1795 | 94 | Name: name, | 94 | Name: name, |
1796 | 95 | Value: value, | 95 | Value: value, |
1797 | 96 | Raw: line, | 96 | Raw: line, |
1799 | 97 | @@ -129,59 +108,12 @@ | 97 | @@ -125,59 +104,12 @@ |
1800 | 98 | return cookies | 98 | return cookies |
1801 | 99 | } | 99 | } |
1802 | 100 | 100 | ||
1803 | @@ -156,7 +156,7 @@ | |||
1804 | 156 | lines, ok := h["Cookie"] | 156 | lines, ok := h["Cookie"] |
1805 | 157 | if !ok { | 157 | if !ok { |
1806 | 158 | return cookies | 158 | return cookies |
1808 | 159 | @@ -213,7 +145,7 @@ | 159 | @@ -209,7 +141,7 @@ |
1809 | 160 | if !success { | 160 | if !success { |
1810 | 161 | continue | 161 | continue |
1811 | 162 | } | 162 | } |
1812 | @@ -167,8 +167,8 @@ | |||
1813 | 167 | } | 167 | } |
1814 | 168 | 168 | ||
1815 | 169 | === modified file 'http13client/header.go' | 169 | === modified file 'http13client/header.go' |
1818 | 170 | --- http13client/header.go 2014-03-19 20:20:19 +0000 | 170 | --- http13client/header.go 2014-06-20 11:00:47 +0000 |
1819 | 171 | +++ http13client/header.go 2014-03-19 22:27:37 +0000 | 171 | +++ http13client/header.go 2014-06-20 12:00:22 +0000 |
1820 | 172 | @@ -5,176 +5,9 @@ | 172 | @@ -5,176 +5,9 @@ |
1821 | 173 | package http | 173 | package http |
1822 | 174 | 174 | ||
1823 | @@ -348,8 +348,8 @@ | |||
1824 | 348 | // token must be all lowercase. | 348 | // token must be all lowercase. |
1825 | 349 | 349 | ||
1826 | 350 | === modified file 'http13client/request.go' | 350 | === modified file 'http13client/request.go' |
1829 | 351 | --- http13client/request.go 2014-03-19 20:20:19 +0000 | 351 | --- http13client/request.go 2014-06-20 11:00:47 +0000 |
1830 | 352 | +++ http13client/request.go 2014-03-19 22:27:37 +0000 | 352 | +++ http13client/request.go 2014-06-20 12:05:53 +0000 |
1831 | 353 | @@ -16,6 +16,7 @@ | 353 | @@ -16,6 +16,7 @@ |
1832 | 354 | "io/ioutil" | 354 | "io/ioutil" |
1833 | 355 | "mime" | 355 | "mime" |
1834 | @@ -358,25 +358,25 @@ | |||
1835 | 358 | "net/textproto" | 358 | "net/textproto" |
1836 | 359 | "net/url" | 359 | "net/url" |
1837 | 360 | "strconv" | 360 | "strconv" |
1842 | 361 | @@ -103,7 +104,7 @@ | 361 | @@ -121,7 +122,7 @@ |
1843 | 362 | // The request parser implements this by canonicalizing the | 362 | // added and may override values in Header. |
1844 | 363 | // name, making the first character and any characters | 363 | // |
1845 | 364 | // following a hyphen uppercase and the rest lowercase. | 364 | // See the documentation for the Request.Write method. |
1846 | 365 | - Header Header | 365 | - Header Header |
1847 | 366 | + Header http.Header | 366 | + Header http.Header |
1848 | 367 | 367 | ||
1849 | 368 | // Body is the request's body. | 368 | // Body is the request's body. |
1850 | 369 | // | 369 | // |
1855 | 370 | @@ -164,7 +165,7 @@ | 370 | @@ -199,7 +200,7 @@ |
1856 | 371 | // For server requests, Trailer is only populated after Body has been | 371 | // not mutate Trailer. |
1857 | 372 | // closed or fully consumed. | 372 | // |
1858 | 373 | // Trailer support is only partially complete. | 373 | // Few HTTP clients, servers, or proxies support HTTP trailers. |
1859 | 374 | - Trailer Header | 374 | - Trailer Header |
1860 | 375 | + Trailer http.Header | 375 | + Trailer http.Header |
1861 | 376 | 376 | ||
1862 | 377 | // RemoteAddr allows HTTP servers and other software to record | 377 | // RemoteAddr allows HTTP servers and other software to record |
1863 | 378 | // the network address that sent the request, usually for | 378 | // the network address that sent the request, usually for |
1865 | 379 | @@ -204,7 +205,7 @@ | 379 | @@ -239,7 +240,7 @@ |
1866 | 380 | } | 380 | } |
1867 | 381 | 381 | ||
1868 | 382 | // Cookies parses and returns the HTTP cookies sent with the request. | 382 | // Cookies parses and returns the HTTP cookies sent with the request. |
1869 | @@ -385,7 +385,7 @@ | |||
1870 | 385 | return readCookies(r.Header, "") | 385 | return readCookies(r.Header, "") |
1871 | 386 | } | 386 | } |
1872 | 387 | 387 | ||
1874 | 388 | @@ -212,7 +213,7 @@ | 388 | @@ -247,7 +248,7 @@ |
1875 | 389 | 389 | ||
1876 | 390 | // Cookie returns the named cookie provided in the request or | 390 | // Cookie returns the named cookie provided in the request or |
1877 | 391 | // ErrNoCookie if not found. | 391 | // ErrNoCookie if not found. |
1878 | @@ -394,7 +394,7 @@ | |||
1879 | 394 | for _, c := range readCookies(r.Header, name) { | 394 | for _, c := range readCookies(r.Header, name) { |
1880 | 395 | return c, nil | 395 | return c, nil |
1881 | 396 | } | 396 | } |
1883 | 397 | @@ -223,7 +224,7 @@ | 397 | @@ -258,7 +259,7 @@ |
1884 | 398 | // AddCookie does not attach more than one Cookie header field. That | 398 | // AddCookie does not attach more than one Cookie header field. That |
1885 | 399 | // means all cookies, if any, are written into the same line, | 399 | // means all cookies, if any, are written into the same line, |
1886 | 400 | // separated by semicolon. | 400 | // separated by semicolon. |
1887 | @@ -403,7 +403,7 @@ | |||
1888 | 403 | s := fmt.Sprintf("%s=%s", sanitizeCookieName(c.Name), sanitizeCookieValue(c.Value)) | 403 | s := fmt.Sprintf("%s=%s", sanitizeCookieName(c.Name), sanitizeCookieValue(c.Value)) |
1889 | 404 | if c := r.Header.Get("Cookie"); c != "" { | 404 | if c := r.Header.Get("Cookie"); c != "" { |
1890 | 405 | r.Header.Set("Cookie", c+"; "+s) | 405 | r.Header.Set("Cookie", c+"; "+s) |
1892 | 406 | @@ -326,7 +327,7 @@ | 406 | @@ -361,7 +362,7 @@ |
1893 | 407 | } | 407 | } |
1894 | 408 | 408 | ||
1895 | 409 | // extraHeaders may be nil | 409 | // extraHeaders may be nil |
1896 | @@ -412,7 +412,7 @@ | |||
1897 | 412 | host := req.Host | 412 | host := req.Host |
1898 | 413 | if host == "" { | 413 | if host == "" { |
1899 | 414 | if req.URL == nil { | 414 | if req.URL == nil { |
1901 | 415 | @@ -456,7 +457,7 @@ | 415 | @@ -490,7 +491,7 @@ |
1902 | 416 | Proto: "HTTP/1.1", | 416 | Proto: "HTTP/1.1", |
1903 | 417 | ProtoMajor: 1, | 417 | ProtoMajor: 1, |
1904 | 418 | ProtoMinor: 1, | 418 | ProtoMinor: 1, |
1905 | @@ -421,7 +421,7 @@ | |||
1906 | 421 | Body: rc, | 421 | Body: rc, |
1907 | 422 | Host: u.Host, | 422 | Host: u.Host, |
1908 | 423 | } | 423 | } |
1910 | 424 | @@ -571,7 +572,7 @@ | 424 | @@ -605,7 +606,7 @@ |
1911 | 425 | if err != nil { | 425 | if err != nil { |
1912 | 426 | return nil, err | 426 | return nil, err |
1913 | 427 | } | 427 | } |
1914 | @@ -430,7 +430,7 @@ | |||
1915 | 430 | 430 | ||
1916 | 431 | // RFC2616: Must treat | 431 | // RFC2616: Must treat |
1917 | 432 | // GET /index.html HTTP/1.1 | 432 | // GET /index.html HTTP/1.1 |
1919 | 433 | @@ -582,7 +583,7 @@ | 433 | @@ -616,7 +617,7 @@ |
1920 | 434 | // the same. In the second case, any Host line is ignored. | 434 | // the same. In the second case, any Host line is ignored. |
1921 | 435 | req.Host = req.URL.Host | 435 | req.Host = req.URL.Host |
1922 | 436 | if req.Host == "" { | 436 | if req.Host == "" { |
1923 | @@ -439,7 +439,7 @@ | |||
1924 | 439 | } | 439 | } |
1925 | 440 | delete(req.Header, "Host") | 440 | delete(req.Header, "Host") |
1926 | 441 | 441 | ||
1928 | 442 | @@ -630,12 +631,12 @@ | 442 | @@ -638,12 +639,12 @@ |
1929 | 443 | // | 443 | // |
1930 | 444 | // MaxBytesReader prevents clients from accidentally or maliciously | 444 | // MaxBytesReader prevents clients from accidentally or maliciously |
1931 | 445 | // sending a large request and wasting server resources. | 445 | // sending a large request and wasting server resources. |
1932 | @@ -454,7 +454,7 @@ | |||
1933 | 454 | r io.ReadCloser // underlying reader | 454 | r io.ReadCloser // underlying reader |
1934 | 455 | n int64 // max bytes remaining | 455 | n int64 // max bytes remaining |
1935 | 456 | stopped bool | 456 | stopped bool |
1937 | 457 | @@ -645,9 +646,6 @@ | 457 | @@ -653,9 +654,6 @@ |
1938 | 458 | if l.n <= 0 { | 458 | if l.n <= 0 { |
1939 | 459 | if !l.stopped { | 459 | if !l.stopped { |
1940 | 460 | l.stopped = true | 460 | l.stopped = true |
1941 | @@ -464,7 +464,7 @@ | |||
1942 | 464 | } | 464 | } |
1943 | 465 | return 0, errors.New("http: request body too large") | 465 | return 0, errors.New("http: request body too large") |
1944 | 466 | } | 466 | } |
1946 | 467 | @@ -852,16 +850,16 @@ | 467 | @@ -858,18 +856,18 @@ |
1947 | 468 | } | 468 | } |
1948 | 469 | 469 | ||
1949 | 470 | func (r *Request) expectsContinue() bool { | 470 | func (r *Request) expectsContinue() bool { |
1950 | @@ -484,11 +484,13 @@ | |||
1951 | 484 | - return hasToken(r.Header.get("Connection"), "close") | 484 | - return hasToken(r.Header.get("Connection"), "close") |
1952 | 485 | + return hasToken(r.Header.Get("Connection"), "close") | 485 | + return hasToken(r.Header.Get("Connection"), "close") |
1953 | 486 | } | 486 | } |
1954 | 487 | |||
1955 | 488 | func (r *Request) closeBody() { | ||
1956 | 487 | 489 | ||
1957 | 488 | === modified file 'http13client/response.go' | 490 | === modified file 'http13client/response.go' |
1961 | 489 | --- http13client/response.go 2014-03-19 20:20:19 +0000 | 491 | --- http13client/response.go 2014-06-20 11:00:47 +0000 |
1962 | 490 | +++ http13client/response.go 2014-03-19 22:27:37 +0000 | 492 | +++ http13client/response.go 2014-06-20 12:05:53 +0000 |
1963 | 491 | @@ -11,6 +11,7 @@ | 493 | @@ -12,6 +12,7 @@ |
1964 | 492 | "crypto/tls" | 494 | "crypto/tls" |
1965 | 493 | "errors" | 495 | "errors" |
1966 | 494 | "io" | 496 | "io" |
1967 | @@ -496,7 +498,7 @@ | |||
1968 | 496 | "net/textproto" | 498 | "net/textproto" |
1969 | 497 | "net/url" | 499 | "net/url" |
1970 | 498 | "strconv" | 500 | "strconv" |
1972 | 499 | @@ -40,7 +41,7 @@ | 501 | @@ -41,7 +42,7 @@ |
1973 | 500 | // omitted from Header. | 502 | // omitted from Header. |
1974 | 501 | // | 503 | // |
1975 | 502 | // Keys in the map are canonicalized (see CanonicalHeaderKey). | 504 | // Keys in the map are canonicalized (see CanonicalHeaderKey). |
1976 | @@ -505,7 +507,7 @@ | |||
1977 | 505 | 507 | ||
1978 | 506 | // Body represents the response body. | 508 | // Body represents the response body. |
1979 | 507 | // | 509 | // |
1981 | 508 | @@ -69,7 +70,7 @@ | 510 | @@ -71,7 +72,7 @@ |
1982 | 509 | 511 | ||
1983 | 510 | // Trailer maps trailer keys to values, in the same | 512 | // Trailer maps trailer keys to values, in the same |
1984 | 511 | // format as the header. | 513 | // format as the header. |
1985 | @@ -514,7 +516,7 @@ | |||
1986 | 514 | 516 | ||
1987 | 515 | // The Request that was sent to obtain this Response. | 517 | // The Request that was sent to obtain this Response. |
1988 | 516 | // Request's Body is nil (having already been consumed). | 518 | // Request's Body is nil (having already been consumed). |
1990 | 517 | @@ -84,7 +85,7 @@ | 519 | @@ -86,7 +87,7 @@ |
1991 | 518 | } | 520 | } |
1992 | 519 | 521 | ||
1993 | 520 | // Cookies parses and returns the cookies set in the Set-Cookie headers. | 522 | // Cookies parses and returns the cookies set in the Set-Cookie headers. |
1994 | @@ -523,7 +525,7 @@ | |||
1995 | 523 | return readSetCookies(r.Header) | 525 | return readSetCookies(r.Header) |
1996 | 524 | } | 526 | } |
1997 | 525 | 527 | ||
1999 | 526 | @@ -153,7 +154,7 @@ | 528 | @@ -155,7 +156,7 @@ |
2000 | 527 | } | 529 | } |
2001 | 528 | return nil, err | 530 | return nil, err |
2002 | 529 | } | 531 | } |
2003 | @@ -532,7 +534,7 @@ | |||
2004 | 532 | 534 | ||
2005 | 533 | fixPragmaCacheControl(resp.Header) | 535 | fixPragmaCacheControl(resp.Header) |
2006 | 534 | 536 | ||
2008 | 535 | @@ -169,7 +170,7 @@ | 537 | @@ -171,7 +172,7 @@ |
2009 | 536 | // Pragma: no-cache | 538 | // Pragma: no-cache |
2010 | 537 | // like | 539 | // like |
2011 | 538 | // Cache-Control: no-cache | 540 | // Cache-Control: no-cache |
2012 | @@ -543,17 +545,17 @@ | |||
2013 | 543 | header["Cache-Control"] = []string{"no-cache"} | 545 | header["Cache-Control"] = []string{"no-cache"} |
2014 | 544 | 546 | ||
2015 | 545 | === modified file 'http13client/transfer.go' | 547 | === modified file 'http13client/transfer.go' |
2018 | 546 | --- http13client/transfer.go 2014-03-19 20:20:19 +0000 | 548 | --- http13client/transfer.go 2014-06-20 11:00:47 +0000 |
2019 | 547 | +++ http13client/transfer.go 2014-03-19 22:27:37 +0000 | 549 | +++ http13client/transfer.go 2014-06-20 12:05:53 +0000 |
2020 | 548 | @@ -11,6 +11,7 @@ | 550 | @@ -11,6 +11,7 @@ |
2021 | 549 | "fmt" | 551 | "fmt" |
2022 | 550 | "io" | 552 | "io" |
2023 | 551 | "io/ioutil" | 553 | "io/ioutil" |
2024 | 552 | + "net/http" | 554 | + "net/http" |
2025 | 553 | "net/textproto" | 555 | "net/textproto" |
2026 | 556 | "sort" | ||
2027 | 554 | "strconv" | 557 | "strconv" |
2030 | 555 | "strings" | 558 | @@ -37,7 +38,7 @@ |
2029 | 556 | @@ -36,7 +37,7 @@ | ||
2031 | 557 | ContentLength int64 // -1 means unknown, 0 means exactly none | 559 | ContentLength int64 // -1 means unknown, 0 means exactly none |
2032 | 558 | Close bool | 560 | Close bool |
2033 | 559 | TransferEncoding []string | 561 | TransferEncoding []string |
2034 | @@ -562,16 +564,16 @@ | |||
2035 | 562 | } | 564 | } |
2036 | 563 | 565 | ||
2037 | 564 | func newTransferWriter(r interface{}) (t *transferWriter, err error) { | 566 | func newTransferWriter(r interface{}) (t *transferWriter, err error) { |
2041 | 565 | @@ -174,7 +175,7 @@ | 567 | @@ -171,7 +172,7 @@ |
2042 | 566 | io.WriteString(w, "Trailer: ") | 568 | if t.Trailer != nil { |
2043 | 567 | needComma := false | 569 | keys := make([]string, 0, len(t.Trailer)) |
2044 | 568 | for k := range t.Trailer { | 570 | for k := range t.Trailer { |
2045 | 569 | - k = CanonicalHeaderKey(k) | 571 | - k = CanonicalHeaderKey(k) |
2046 | 570 | + k = http.CanonicalHeaderKey(k) | 572 | + k = http.CanonicalHeaderKey(k) |
2047 | 571 | switch k { | 573 | switch k { |
2048 | 572 | case "Transfer-Encoding", "Trailer", "Content-Length": | 574 | case "Transfer-Encoding", "Trailer", "Content-Length": |
2049 | 573 | return &badStringError{"invalid Trailer key", k} | 575 | return &badStringError{"invalid Trailer key", k} |
2051 | 574 | @@ -237,7 +238,7 @@ | 576 | @@ -243,7 +244,7 @@ |
2052 | 575 | 577 | ||
2053 | 576 | type transferReader struct { | 578 | type transferReader struct { |
2054 | 577 | // Input | 579 | // Input |
2055 | @@ -580,7 +582,7 @@ | |||
2056 | 580 | StatusCode int | 582 | StatusCode int |
2057 | 581 | RequestMethod string | 583 | RequestMethod string |
2058 | 582 | ProtoMajor int | 584 | ProtoMajor int |
2060 | 583 | @@ -247,7 +248,7 @@ | 585 | @@ -253,7 +254,7 @@ |
2061 | 584 | ContentLength int64 | 586 | ContentLength int64 |
2062 | 585 | TransferEncoding []string | 587 | TransferEncoding []string |
2063 | 586 | Close bool | 588 | Close bool |
2064 | @@ -589,7 +591,7 @@ | |||
2065 | 589 | } | 591 | } |
2066 | 590 | 592 | ||
2067 | 591 | // bodyAllowedForStatus reports whether a given response status code | 593 | // bodyAllowedForStatus reports whether a given response status code |
2069 | 592 | @@ -308,7 +309,7 @@ | 594 | @@ -330,7 +331,7 @@ |
2070 | 593 | return err | 595 | return err |
2071 | 594 | } | 596 | } |
2072 | 595 | if isResponse && t.RequestMethod == "HEAD" { | 597 | if isResponse && t.RequestMethod == "HEAD" { |
2073 | @@ -598,7 +600,7 @@ | |||
2074 | 598 | return err | 600 | return err |
2075 | 599 | } else { | 601 | } else { |
2076 | 600 | t.ContentLength = n | 602 | t.ContentLength = n |
2078 | 601 | @@ -386,7 +387,7 @@ | 603 | @@ -408,7 +409,7 @@ |
2079 | 602 | func isIdentity(te []string) bool { return len(te) == 1 && te[0] == "identity" } | 604 | func isIdentity(te []string) bool { return len(te) == 1 && te[0] == "identity" } |
2080 | 603 | 605 | ||
2081 | 604 | // Sanitize transfer encoding | 606 | // Sanitize transfer encoding |
2082 | @@ -607,7 +609,7 @@ | |||
2083 | 607 | raw, present := header["Transfer-Encoding"] | 609 | raw, present := header["Transfer-Encoding"] |
2084 | 608 | if !present { | 610 | if !present { |
2085 | 609 | return nil, nil | 611 | return nil, nil |
2087 | 610 | @@ -429,7 +430,7 @@ | 612 | @@ -451,7 +452,7 @@ |
2088 | 611 | // Determine the expected body length, using RFC 2616 Section 4.4. This | 613 | // Determine the expected body length, using RFC 2616 Section 4.4. This |
2089 | 612 | // function is not a method, because ultimately it should be shared by | 614 | // function is not a method, because ultimately it should be shared by |
2090 | 613 | // ReadResponse and ReadRequest. | 615 | // ReadResponse and ReadRequest. |
2091 | @@ -616,7 +618,7 @@ | |||
2092 | 616 | 618 | ||
2093 | 617 | // Logic based on response type or status | 619 | // Logic based on response type or status |
2094 | 618 | if noBodyExpected(requestMethod) { | 620 | if noBodyExpected(requestMethod) { |
2096 | 619 | @@ -449,7 +450,7 @@ | 621 | @@ -471,7 +472,7 @@ |
2097 | 620 | } | 622 | } |
2098 | 621 | 623 | ||
2099 | 622 | // Logic based on Content-Length | 624 | // Logic based on Content-Length |
2100 | @@ -625,7 +627,7 @@ | |||
2101 | 625 | if cl != "" { | 627 | if cl != "" { |
2102 | 626 | n, err := parseContentLength(cl) | 628 | n, err := parseContentLength(cl) |
2103 | 627 | if err != nil { | 629 | if err != nil { |
2105 | 628 | @@ -475,18 +476,18 @@ | 630 | @@ -497,18 +498,18 @@ |
2106 | 629 | // Determine whether to hang up after sending a request and body, or | 631 | // Determine whether to hang up after sending a request and body, or |
2107 | 630 | // receiving a response and body | 632 | // receiving a response and body |
2108 | 631 | // 'header' is the request headers | 633 | // 'header' is the request headers |
2109 | @@ -647,7 +649,7 @@ | |||
2110 | 647 | header.Del("Connection") | 649 | header.Del("Connection") |
2111 | 648 | return true | 650 | return true |
2112 | 649 | } | 651 | } |
2114 | 650 | @@ -495,17 +496,17 @@ | 652 | @@ -517,17 +518,17 @@ |
2115 | 651 | } | 653 | } |
2116 | 652 | 654 | ||
2117 | 653 | // Parse the trailer header | 655 | // Parse the trailer header |
2118 | @@ -669,22 +671,28 @@ | |||
2119 | 669 | switch key { | 671 | switch key { |
2120 | 670 | case "Transfer-Encoding", "Trailer", "Content-Length": | 672 | case "Transfer-Encoding", "Trailer", "Content-Length": |
2121 | 671 | return nil, &badStringError{"bad trailer key", key} | 673 | return nil, &badStringError{"bad trailer key", key} |
2123 | 672 | @@ -642,9 +643,9 @@ | 674 | @@ -664,14 +665,14 @@ |
2124 | 673 | } | 675 | } |
2125 | 674 | switch rr := b.hdr.(type) { | 676 | switch rr := b.hdr.(type) { |
2126 | 675 | case *Request: | 677 | case *Request: |
2129 | 676 | - rr.Trailer = Header(hdr) | 678 | - mergeSetHeader(&rr.Trailer, Header(hdr)) |
2130 | 677 | + rr.Trailer = http.Header(hdr) | 679 | + mergeSetHeader(&rr.Trailer, http.Header(hdr)) |
2131 | 678 | case *Response: | 680 | case *Response: |
2134 | 679 | - rr.Trailer = Header(hdr) | 681 | - mergeSetHeader(&rr.Trailer, Header(hdr)) |
2135 | 680 | + rr.Trailer = http.Header(hdr) | 682 | + mergeSetHeader(&rr.Trailer, http.Header(hdr)) |
2136 | 681 | } | 683 | } |
2137 | 682 | return nil | 684 | return nil |
2138 | 683 | } | 685 | } |
2139 | 686 | |||
2140 | 687 | -func mergeSetHeader(dst *Header, src Header) { | ||
2141 | 688 | +func mergeSetHeader(dst *http.Header, src http.Header) { | ||
2142 | 689 | if *dst == nil { | ||
2143 | 690 | *dst = src | ||
2144 | 691 | return | ||
2145 | 684 | 692 | ||
2146 | 685 | === modified file 'http13client/transport.go' | 693 | === modified file 'http13client/transport.go' |
2149 | 686 | --- http13client/transport.go 2014-03-19 20:20:19 +0000 | 694 | --- http13client/transport.go 2014-06-20 11:00:47 +0000 |
2150 | 687 | +++ http13client/transport.go 2014-03-19 22:27:37 +0000 | 695 | +++ http13client/transport.go 2014-06-20 12:05:53 +0000 |
2151 | 688 | @@ -18,6 +18,7 @@ | 696 | @@ -18,6 +18,7 @@ |
2152 | 689 | "io" | 697 | "io" |
2153 | 690 | "log" | 698 | "log" |
2154 | @@ -693,7 +701,7 @@ | |||
2155 | 693 | "net/url" | 701 | "net/url" |
2156 | 694 | "os" | 702 | "os" |
2157 | 695 | "strings" | 703 | "strings" |
2159 | 696 | @@ -144,12 +145,12 @@ | 704 | @@ -147,12 +148,12 @@ |
2160 | 697 | // optional extra headers to write. | 705 | // optional extra headers to write. |
2161 | 698 | type transportRequest struct { | 706 | type transportRequest struct { |
2162 | 699 | *Request // original request, not to be mutated | 707 | *Request // original request, not to be mutated |
2163 | @@ -709,7 +717,7 @@ | |||
2164 | 709 | } | 717 | } |
2165 | 710 | return tr.extra | 718 | return tr.extra |
2166 | 711 | } | 719 | } |
2168 | 712 | @@ -512,7 +513,7 @@ | 720 | @@ -519,7 +520,7 @@ |
2169 | 713 | case cm.targetScheme == "http": | 721 | case cm.targetScheme == "http": |
2170 | 714 | pconn.isProxy = true | 722 | pconn.isProxy = true |
2171 | 715 | if pa != "" { | 723 | if pa != "" { |
2172 | @@ -718,7 +726,7 @@ | |||
2173 | 718 | h.Set("Proxy-Authorization", pa) | 726 | h.Set("Proxy-Authorization", pa) |
2174 | 719 | } | 727 | } |
2175 | 720 | } | 728 | } |
2177 | 721 | @@ -521,7 +522,7 @@ | 729 | @@ -528,7 +529,7 @@ |
2178 | 722 | Method: "CONNECT", | 730 | Method: "CONNECT", |
2179 | 723 | URL: &url.URL{Opaque: cm.targetAddr}, | 731 | URL: &url.URL{Opaque: cm.targetAddr}, |
2180 | 724 | Host: cm.targetAddr, | 732 | Host: cm.targetAddr, |
2181 | @@ -727,7 +735,7 @@ | |||
2182 | 727 | } | 735 | } |
2183 | 728 | if pa != "" { | 736 | if pa != "" { |
2184 | 729 | connectReq.Header.Set("Proxy-Authorization", pa) | 737 | connectReq.Header.Set("Proxy-Authorization", pa) |
2186 | 730 | @@ -735,7 +736,7 @@ | 738 | @@ -748,7 +749,7 @@ |
2187 | 731 | // mutateHeaderFunc is an optional func to modify extra | 739 | // mutateHeaderFunc is an optional func to modify extra |
2188 | 732 | // headers on each outbound request before it's written. (the | 740 | // headers on each outbound request before it's written. (the |
2189 | 733 | // original Request given to RoundTrip is not modified) | 741 | // original Request given to RoundTrip is not modified) |
2190 | @@ -735,5 +743,5 @@ | |||
2191 | 735 | + mutateHeaderFunc func(http.Header) | 743 | + mutateHeaderFunc func(http.Header) |
2192 | 736 | } | 744 | } |
2193 | 737 | 745 | ||
2195 | 738 | func (pc *persistConn) isBroken() bool { | 746 | // isBroken reports whether this connection is in a known broken state. |
2196 | 739 | 747 | ||
2197 | 740 | 748 | ||
2198 | === modified file 'http13client/_patches/fix_status.patch' | |||
2199 | --- http13client/_patches/fix_status.patch 2014-03-19 23:43:25 +0000 | |||
2200 | +++ http13client/_patches/fix_status.patch 2014-06-20 13:02:58 +0000 | |||
2201 | @@ -1,7 +1,7 @@ | |||
2202 | 1 | === modified file 'http13client/client.go' | 1 | === modified file 'http13client/client.go' |
2206 | 2 | --- http13client/client.go 2014-03-19 23:13:58 +0000 | 2 | --- http13client/client.go 2014-06-20 12:46:25 +0000 |
2207 | 3 | +++ http13client/client.go 2014-03-19 23:38:11 +0000 | 3 | +++ http13client/client.go 2014-06-20 12:46:45 +0000 |
2208 | 4 | @@ -210,7 +210,7 @@ | 4 | @@ -217,7 +217,7 @@ |
2209 | 5 | // automatically redirect. | 5 | // automatically redirect. |
2210 | 6 | func shouldRedirectGet(statusCode int) bool { | 6 | func shouldRedirectGet(statusCode int) bool { |
2211 | 7 | switch statusCode { | 7 | switch statusCode { |
2212 | @@ -10,7 +10,7 @@ | |||
2213 | 10 | return true | 10 | return true |
2214 | 11 | } | 11 | } |
2215 | 12 | return false | 12 | return false |
2217 | 13 | @@ -220,7 +220,7 @@ | 13 | @@ -227,7 +227,7 @@ |
2218 | 14 | // automatically redirect. | 14 | // automatically redirect. |
2219 | 15 | func shouldRedirectPost(statusCode int) bool { | 15 | func shouldRedirectPost(statusCode int) bool { |
2220 | 16 | switch statusCode { | 16 | switch statusCode { |
2221 | @@ -21,9 +21,9 @@ | |||
2222 | 21 | return false | 21 | return false |
2223 | 22 | 22 | ||
2224 | 23 | === modified file 'http13client/client_test.go' | 23 | === modified file 'http13client/client_test.go' |
2228 | 24 | --- http13client/client_test.go 2014-03-19 23:13:58 +0000 | 24 | --- http13client/client_test.go 2014-06-20 12:46:25 +0000 |
2229 | 25 | +++ http13client/client_test.go 2014-03-19 23:39:48 +0000 | 25 | +++ http13client/client_test.go 2014-06-20 12:46:45 +0000 |
2230 | 26 | @@ -202,7 +202,7 @@ | 26 | @@ -204,7 +204,7 @@ |
2231 | 27 | } | 27 | } |
2232 | 28 | } | 28 | } |
2233 | 29 | if n < 15 { | 29 | if n < 15 { |
2234 | @@ -32,7 +32,7 @@ | |||
2235 | 32 | return | 32 | return |
2236 | 33 | } | 33 | } |
2237 | 34 | fmt.Fprintf(w, "n=%d", n) | 34 | fmt.Fprintf(w, "n=%d", n) |
2239 | 35 | @@ -324,7 +324,7 @@ | 35 | @@ -326,7 +326,7 @@ |
2240 | 36 | } | 36 | } |
2241 | 37 | if r.URL.Path == "/" { | 37 | if r.URL.Path == "/" { |
2242 | 38 | http.SetCookie(w, expectedCookies[1]) | 38 | http.SetCookie(w, expectedCookies[1]) |
2243 | @@ -41,7 +41,7 @@ | |||
2244 | 41 | } else { | 41 | } else { |
2245 | 42 | http.SetCookie(w, expectedCookies[2]) | 42 | http.SetCookie(w, expectedCookies[2]) |
2246 | 43 | w.Write([]byte("hello")) | 43 | w.Write([]byte("hello")) |
2248 | 44 | @@ -783,7 +783,7 @@ | 44 | @@ -785,7 +785,7 @@ |
2249 | 45 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 45 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
2250 | 46 | if r.URL.Path == "/" { | 46 | if r.URL.Path == "/" { |
2251 | 47 | sawRoot <- true | 47 | sawRoot <- true |
2252 | @@ -50,7 +50,7 @@ | |||
2253 | 50 | return | 50 | return |
2254 | 51 | } | 51 | } |
2255 | 52 | if r.URL.Path == "/slow" { | 52 | if r.URL.Path == "/slow" { |
2257 | 53 | @@ -844,7 +844,7 @@ | 53 | @@ -846,7 +846,7 @@ |
2258 | 54 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 54 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
2259 | 55 | saw <- r.RemoteAddr | 55 | saw <- r.RemoteAddr |
2260 | 56 | if r.URL.Path == "/" { | 56 | if r.URL.Path == "/" { |
2261 | @@ -61,9 +61,9 @@ | |||
2262 | 61 | defer ts.Close() | 61 | defer ts.Close() |
2263 | 62 | 62 | ||
2264 | 63 | === modified file 'http13client/request_test.go' | 63 | === modified file 'http13client/request_test.go' |
2268 | 64 | --- http13client/request_test.go 2014-03-19 23:13:58 +0000 | 64 | --- http13client/request_test.go 2014-06-20 12:46:25 +0000 |
2269 | 65 | +++ http13client/request_test.go 2014-03-19 23:40:12 +0000 | 65 | +++ http13client/request_test.go 2014-06-20 12:46:45 +0000 |
2270 | 66 | @@ -164,11 +164,11 @@ | 66 | @@ -182,11 +182,11 @@ |
2271 | 67 | switch r.URL.Path { | 67 | switch r.URL.Path { |
2272 | 68 | case "/": | 68 | case "/": |
2273 | 69 | w.Header().Set("Location", "/foo/") | 69 | w.Header().Set("Location", "/foo/") |
2274 | @@ -79,9 +79,9 @@ | |||
2275 | 79 | defer ts.Close() | 79 | defer ts.Close() |
2276 | 80 | 80 | ||
2277 | 81 | === modified file 'http13client/response.go' | 81 | === modified file 'http13client/response.go' |
2281 | 82 | --- http13client/response.go 2014-03-19 23:13:58 +0000 | 82 | --- http13client/response.go 2014-06-20 12:46:25 +0000 |
2282 | 83 | +++ http13client/response.go 2014-03-19 23:38:56 +0000 | 83 | +++ http13client/response.go 2014-06-20 12:46:45 +0000 |
2283 | 84 | @@ -204,9 +204,8 @@ | 84 | @@ -205,9 +205,8 @@ |
2284 | 85 | // Status line | 85 | // Status line |
2285 | 86 | text := r.Status | 86 | text := r.Status |
2286 | 87 | if text == "" { | 87 | if text == "" { |
2287 | @@ -94,10 +94,23 @@ | |||
2288 | 94 | } | 94 | } |
2289 | 95 | } | 95 | } |
2290 | 96 | 96 | ||
2291 | 97 | === modified file 'http13client/responsewrite_test.go' | ||
2292 | 98 | --- http13client/responsewrite_test.go 2014-06-20 12:46:25 +0000 | ||
2293 | 99 | +++ http13client/responsewrite_test.go 2014-06-20 12:47:05 +0000 | ||
2294 | 100 | @@ -197,7 +197,7 @@ | ||
2295 | 101 | // there were two. | ||
2296 | 102 | { | ||
2297 | 103 | Response{ | ||
2298 | 104 | - StatusCode: StatusOK, | ||
2299 | 105 | + StatusCode: http.StatusOK, | ||
2300 | 106 | ProtoMajor: 1, | ||
2301 | 107 | ProtoMinor: 1, | ||
2302 | 108 | Request: &Request{Method: "POST"}, | ||
2303 | 109 | |||
2304 | 97 | === modified file 'http13client/transport_test.go' | 110 | === modified file 'http13client/transport_test.go' |
2308 | 98 | --- http13client/transport_test.go 2014-03-19 23:13:58 +0000 | 111 | --- http13client/transport_test.go 2014-06-20 12:46:25 +0000 |
2309 | 99 | +++ http13client/transport_test.go 2014-03-19 23:40:39 +0000 | 112 | +++ http13client/transport_test.go 2014-06-20 12:46:45 +0000 |
2310 | 100 | @@ -968,7 +968,7 @@ | 113 | @@ -1004,7 +1004,7 @@ |
2311 | 101 | defer afterTest(t) | 114 | defer afterTest(t) |
2312 | 102 | const deniedMsg = "sorry, denied." | 115 | const deniedMsg = "sorry, denied." |
2313 | 103 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 116 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
2314 | @@ -106,7 +119,7 @@ | |||
2315 | 106 | })) | 119 | })) |
2316 | 107 | defer ts.Close() | 120 | defer ts.Close() |
2317 | 108 | tr := &Transport{} | 121 | tr := &Transport{} |
2319 | 109 | @@ -992,7 +992,7 @@ | 122 | @@ -1028,7 +1028,7 @@ |
2320 | 110 | func TestChunkedNoContent(t *testing.T) { | 123 | func TestChunkedNoContent(t *testing.T) { |
2321 | 111 | defer afterTest(t) | 124 | defer afterTest(t) |
2322 | 112 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 125 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
2323 | 113 | 126 | ||
2324 | === modified file 'http13client/_patches/fix_tests.patch' | |||
2325 | --- http13client/_patches/fix_tests.patch 2014-03-19 23:13:58 +0000 | |||
2326 | +++ http13client/_patches/fix_tests.patch 2014-06-20 13:02:58 +0000 | |||
2327 | @@ -1,6 +1,6 @@ | |||
2328 | 1 | === modified file 'http13client/client_test.go' | 1 | === modified file 'http13client/client_test.go' |
2331 | 2 | --- http13client/client_test.go 2014-03-19 21:38:56 +0000 | 2 | --- http13client/client_test.go 2014-06-20 11:00:47 +0000 |
2332 | 3 | +++ http13client/client_test.go 2014-03-19 22:27:37 +0000 | 3 | +++ http13client/client_test.go 2014-06-20 12:05:53 +0000 |
2333 | 4 | @@ -15,8 +15,8 @@ | 4 | @@ -15,8 +15,8 @@ |
2334 | 5 | "fmt" | 5 | "fmt" |
2335 | 6 | "io" | 6 | "io" |
2336 | @@ -11,7 +11,7 @@ | |||
2337 | 11 | . "launchpad.net/ubuntu-push/http13client" | 11 | . "launchpad.net/ubuntu-push/http13client" |
2338 | 12 | "net/http/httptest" | 12 | "net/http/httptest" |
2339 | 13 | "net/url" | 13 | "net/url" |
2341 | 14 | @@ -27,7 +27,7 @@ | 14 | @@ -29,7 +29,7 @@ |
2342 | 15 | "time" | 15 | "time" |
2343 | 16 | ) | 16 | ) |
2344 | 17 | 17 | ||
2345 | @@ -20,7 +20,7 @@ | |||
2346 | 20 | w.Header().Set("Last-Modified", "sometime") | 20 | w.Header().Set("Last-Modified", "sometime") |
2347 | 21 | fmt.Fprintf(w, "User-agent: go\nDisallow: /something/") | 21 | fmt.Fprintf(w, "User-agent: go\nDisallow: /something/") |
2348 | 22 | }) | 22 | }) |
2350 | 23 | @@ -193,7 +193,7 @@ | 23 | @@ -195,7 +195,7 @@ |
2351 | 24 | func TestClientRedirects(t *testing.T) { | 24 | func TestClientRedirects(t *testing.T) { |
2352 | 25 | defer afterTest(t) | 25 | defer afterTest(t) |
2353 | 26 | var ts *httptest.Server | 26 | var ts *httptest.Server |
2354 | @@ -29,7 +29,7 @@ | |||
2355 | 29 | n, _ := strconv.Atoi(r.FormValue("n")) | 29 | n, _ := strconv.Atoi(r.FormValue("n")) |
2356 | 30 | // Test Referer header. (7 is arbitrary position to test at) | 30 | // Test Referer header. (7 is arbitrary position to test at) |
2357 | 31 | if n == 7 { | 31 | if n == 7 { |
2359 | 32 | @@ -202,7 +202,7 @@ | 32 | @@ -204,7 +204,7 @@ |
2360 | 33 | } | 33 | } |
2361 | 34 | } | 34 | } |
2362 | 35 | if n < 15 { | 35 | if n < 15 { |
2363 | @@ -38,7 +38,7 @@ | |||
2364 | 38 | return | 38 | return |
2365 | 39 | } | 39 | } |
2366 | 40 | fmt.Fprintf(w, "n=%d", n) | 40 | fmt.Fprintf(w, "n=%d", n) |
2368 | 41 | @@ -271,7 +271,7 @@ | 41 | @@ -273,7 +273,7 @@ |
2369 | 42 | bytes.Buffer | 42 | bytes.Buffer |
2370 | 43 | } | 43 | } |
2371 | 44 | var ts *httptest.Server | 44 | var ts *httptest.Server |
2372 | @@ -47,7 +47,7 @@ | |||
2373 | 47 | log.Lock() | 47 | log.Lock() |
2374 | 48 | fmt.Fprintf(&log.Buffer, "%s %s ", r.Method, r.RequestURI) | 48 | fmt.Fprintf(&log.Buffer, "%s %s ", r.Method, r.RequestURI) |
2375 | 49 | log.Unlock() | 49 | log.Unlock() |
2377 | 50 | @@ -312,21 +312,21 @@ | 50 | @@ -314,21 +314,21 @@ |
2378 | 51 | } | 51 | } |
2379 | 52 | } | 52 | } |
2380 | 53 | 53 | ||
2381 | @@ -75,7 +75,7 @@ | |||
2382 | 75 | w.Write([]byte("hello")) | 75 | w.Write([]byte("hello")) |
2383 | 76 | } | 76 | } |
2384 | 77 | }) | 77 | }) |
2386 | 78 | @@ -334,7 +334,7 @@ | 78 | @@ -336,7 +336,7 @@ |
2387 | 79 | func TestClientSendsCookieFromJar(t *testing.T) { | 79 | func TestClientSendsCookieFromJar(t *testing.T) { |
2388 | 80 | tr := &recordingTransport{} | 80 | tr := &recordingTransport{} |
2389 | 81 | client := &Client{Transport: tr} | 81 | client := &Client{Transport: tr} |
2390 | @@ -84,7 +84,7 @@ | |||
2391 | 84 | us := "http://dummy.faketld/" | 84 | us := "http://dummy.faketld/" |
2392 | 85 | u, _ := url.Parse(us) | 85 | u, _ := url.Parse(us) |
2393 | 86 | client.Jar.SetCookies(u, expectedCookies) | 86 | client.Jar.SetCookies(u, expectedCookies) |
2395 | 87 | @@ -364,19 +364,19 @@ | 87 | @@ -366,19 +366,19 @@ |
2396 | 88 | // scope of all cookies. | 88 | // scope of all cookies. |
2397 | 89 | type TestJar struct { | 89 | type TestJar struct { |
2398 | 90 | m sync.Mutex | 90 | m sync.Mutex |
2399 | @@ -108,7 +108,7 @@ | |||
2400 | 108 | j.m.Lock() | 108 | j.m.Lock() |
2401 | 109 | defer j.m.Unlock() | 109 | defer j.m.Unlock() |
2402 | 110 | return j.perURL[u.Host] | 110 | return j.perURL[u.Host] |
2404 | 111 | @@ -391,7 +391,7 @@ | 111 | @@ -393,7 +393,7 @@ |
2405 | 112 | Jar: new(TestJar), | 112 | Jar: new(TestJar), |
2406 | 113 | } | 113 | } |
2407 | 114 | u, _ := url.Parse(ts.URL) | 114 | u, _ := url.Parse(ts.URL) |
2408 | @@ -117,7 +117,7 @@ | |||
2409 | 117 | resp, err := c.Get(ts.URL) | 117 | resp, err := c.Get(ts.URL) |
2410 | 118 | if err != nil { | 118 | if err != nil { |
2411 | 119 | t.Fatalf("Get: %v", err) | 119 | t.Fatalf("Get: %v", err) |
2413 | 120 | @@ -400,7 +400,7 @@ | 120 | @@ -402,7 +402,7 @@ |
2414 | 121 | matchReturnedCookies(t, expectedCookies, resp.Cookies()) | 121 | matchReturnedCookies(t, expectedCookies, resp.Cookies()) |
2415 | 122 | } | 122 | } |
2416 | 123 | 123 | ||
2417 | @@ -126,7 +126,7 @@ | |||
2418 | 126 | if len(given) != len(expected) { | 126 | if len(given) != len(expected) { |
2419 | 127 | t.Logf("Received cookies: %v", given) | 127 | t.Logf("Received cookies: %v", given) |
2420 | 128 | t.Errorf("Expected %d cookies, got %d", len(expected), len(given)) | 128 | t.Errorf("Expected %d cookies, got %d", len(expected), len(given)) |
2422 | 129 | @@ -421,14 +421,14 @@ | 129 | @@ -423,14 +423,14 @@ |
2423 | 130 | 130 | ||
2424 | 131 | func TestJarCalls(t *testing.T) { | 131 | func TestJarCalls(t *testing.T) { |
2425 | 132 | defer afterTest(t) | 132 | defer afterTest(t) |
2426 | @@ -144,7 +144,7 @@ | |||
2427 | 144 | } | 144 | } |
2428 | 145 | })) | 145 | })) |
2429 | 146 | defer ts.Close() | 146 | defer ts.Close() |
2431 | 147 | @@ -468,11 +468,11 @@ | 147 | @@ -470,11 +470,11 @@ |
2432 | 148 | log bytes.Buffer | 148 | log bytes.Buffer |
2433 | 149 | } | 149 | } |
2434 | 150 | 150 | ||
2435 | @@ -158,7 +158,7 @@ | |||
2436 | 158 | j.logf("Cookies(%q)\n", u) | 158 | j.logf("Cookies(%q)\n", u) |
2437 | 159 | return nil | 159 | return nil |
2438 | 160 | } | 160 | } |
2440 | 161 | @@ -486,11 +486,11 @@ | 161 | @@ -488,11 +488,11 @@ |
2441 | 162 | func TestStreamingGet(t *testing.T) { | 162 | func TestStreamingGet(t *testing.T) { |
2442 | 163 | defer afterTest(t) | 163 | defer afterTest(t) |
2443 | 164 | say := make(chan string) | 164 | say := make(chan string) |
2444 | @@ -173,7 +173,7 @@ | |||
2445 | 173 | } | 173 | } |
2446 | 174 | })) | 174 | })) |
2447 | 175 | defer ts.Close() | 175 | defer ts.Close() |
2449 | 176 | @@ -536,7 +536,7 @@ | 176 | @@ -538,7 +538,7 @@ |
2450 | 177 | // don't send a TCP packet per line of the http request + body. | 177 | // don't send a TCP packet per line of the http request + body. |
2451 | 178 | func TestClientWrites(t *testing.T) { | 178 | func TestClientWrites(t *testing.T) { |
2452 | 179 | defer afterTest(t) | 179 | defer afterTest(t) |
2453 | @@ -182,7 +182,7 @@ | |||
2454 | 182 | })) | 182 | })) |
2455 | 183 | defer ts.Close() | 183 | defer ts.Close() |
2456 | 184 | 184 | ||
2458 | 185 | @@ -568,46 +568,6 @@ | 185 | @@ -570,46 +570,6 @@ |
2459 | 186 | } | 186 | } |
2460 | 187 | } | 187 | } |
2461 | 188 | 188 | ||
2462 | @@ -229,7 +229,7 @@ | |||
2463 | 229 | func TestClientErrorWithRequestURI(t *testing.T) { | 229 | func TestClientErrorWithRequestURI(t *testing.T) { |
2464 | 230 | defer afterTest(t) | 230 | defer afterTest(t) |
2465 | 231 | req, _ := NewRequest("GET", "http://localhost:1234/", nil) | 231 | req, _ := NewRequest("GET", "http://localhost:1234/", nil) |
2467 | 232 | @@ -639,7 +599,7 @@ | 232 | @@ -641,7 +601,7 @@ |
2468 | 233 | 233 | ||
2469 | 234 | func TestClientWithCorrectTLSServerName(t *testing.T) { | 234 | func TestClientWithCorrectTLSServerName(t *testing.T) { |
2470 | 235 | defer afterTest(t) | 235 | defer afterTest(t) |
2471 | @@ -238,7 +238,7 @@ | |||
2472 | 238 | if r.TLS.ServerName != "127.0.0.1" { | 238 | if r.TLS.ServerName != "127.0.0.1" { |
2473 | 239 | t.Errorf("expected client to set ServerName 127.0.0.1, got: %q", r.TLS.ServerName) | 239 | t.Errorf("expected client to set ServerName 127.0.0.1, got: %q", r.TLS.ServerName) |
2474 | 240 | } | 240 | } |
2476 | 241 | @@ -652,33 +612,6 @@ | 241 | @@ -654,33 +614,6 @@ |
2477 | 242 | } | 242 | } |
2478 | 243 | } | 243 | } |
2479 | 244 | 244 | ||
2480 | @@ -272,7 +272,7 @@ | |||
2481 | 272 | // Test for golang.org/issue/5829; the Transport should respect TLSClientConfig.ServerName | 272 | // Test for golang.org/issue/5829; the Transport should respect TLSClientConfig.ServerName |
2482 | 273 | // when not empty. | 273 | // when not empty. |
2483 | 274 | // | 274 | // |
2485 | 275 | @@ -690,7 +623,7 @@ | 275 | @@ -692,7 +625,7 @@ |
2486 | 276 | // The httptest.Server has a cert with "example.com" as its name. | 276 | // The httptest.Server has a cert with "example.com" as its name. |
2487 | 277 | func TestTransportUsesTLSConfigServerName(t *testing.T) { | 277 | func TestTransportUsesTLSConfigServerName(t *testing.T) { |
2488 | 278 | defer afterTest(t) | 278 | defer afterTest(t) |
2489 | @@ -281,7 +281,7 @@ | |||
2490 | 281 | w.Write([]byte("Hello")) | 281 | w.Write([]byte("Hello")) |
2491 | 282 | })) | 282 | })) |
2492 | 283 | defer ts.Close() | 283 | defer ts.Close() |
2494 | 284 | @@ -711,7 +644,7 @@ | 284 | @@ -713,7 +646,7 @@ |
2495 | 285 | 285 | ||
2496 | 286 | func TestResponseSetsTLSConnectionState(t *testing.T) { | 286 | func TestResponseSetsTLSConnectionState(t *testing.T) { |
2497 | 287 | defer afterTest(t) | 287 | defer afterTest(t) |
2498 | @@ -290,7 +290,7 @@ | |||
2499 | 290 | w.Write([]byte("Hello")) | 290 | w.Write([]byte("Hello")) |
2500 | 291 | })) | 291 | })) |
2501 | 292 | defer ts.Close() | 292 | defer ts.Close() |
2503 | 293 | @@ -739,7 +672,7 @@ | 293 | @@ -741,7 +674,7 @@ |
2504 | 294 | // Verify Response.ContentLength is populated. http://golang.org/issue/4126 | 294 | // Verify Response.ContentLength is populated. http://golang.org/issue/4126 |
2505 | 295 | func TestClientHeadContentLength(t *testing.T) { | 295 | func TestClientHeadContentLength(t *testing.T) { |
2506 | 296 | defer afterTest(t) | 296 | defer afterTest(t) |
2507 | @@ -299,7 +299,7 @@ | |||
2508 | 299 | if v := r.FormValue("cl"); v != "" { | 299 | if v := r.FormValue("cl"); v != "" { |
2509 | 300 | w.Header().Set("Content-Length", v) | 300 | w.Header().Set("Content-Length", v) |
2510 | 301 | } | 301 | } |
2512 | 302 | @@ -775,7 +708,7 @@ | 302 | @@ -777,7 +710,7 @@ |
2513 | 303 | func TestEmptyPasswordAuth(t *testing.T) { | 303 | func TestEmptyPasswordAuth(t *testing.T) { |
2514 | 304 | defer afterTest(t) | 304 | defer afterTest(t) |
2515 | 305 | gopher := "gopher" | 305 | gopher := "gopher" |
2516 | @@ -308,7 +308,7 @@ | |||
2517 | 308 | auth := r.Header.Get("Authorization") | 308 | auth := r.Header.Get("Authorization") |
2518 | 309 | if strings.HasPrefix(auth, "Basic ") { | 309 | if strings.HasPrefix(auth, "Basic ") { |
2519 | 310 | encoded := auth[6:] | 310 | encoded := auth[6:] |
2521 | 311 | @@ -847,15 +780,15 @@ | 311 | @@ -849,15 +782,15 @@ |
2522 | 312 | defer afterTest(t) | 312 | defer afterTest(t) |
2523 | 313 | sawRoot := make(chan bool, 1) | 313 | sawRoot := make(chan bool, 1) |
2524 | 314 | sawSlow := make(chan bool, 1) | 314 | sawSlow := make(chan bool, 1) |
2525 | @@ -327,7 +327,7 @@ | |||
2526 | 327 | sawSlow <- true | 327 | sawSlow <- true |
2527 | 328 | time.Sleep(2 * time.Second) | 328 | time.Sleep(2 * time.Second) |
2528 | 329 | return | 329 | return |
2530 | 330 | @@ -908,10 +841,10 @@ | 330 | @@ -910,10 +843,10 @@ |
2531 | 331 | func TestClientRedirectEatsBody(t *testing.T) { | 331 | func TestClientRedirectEatsBody(t *testing.T) { |
2532 | 332 | defer afterTest(t) | 332 | defer afterTest(t) |
2533 | 333 | saw := make(chan string, 2) | 333 | saw := make(chan string, 2) |
2534 | @@ -340,233 +340,50 @@ | |||
2535 | 340 | } | 340 | } |
2536 | 341 | })) | 341 | })) |
2537 | 342 | defer ts.Close() | 342 | defer ts.Close() |
2761 | 343 | 343 | @@ -957,7 +890,7 @@ | |
2762 | 344 | === modified file 'http13client/cookie_test.go' | 344 | |
2763 | 345 | --- http13client/cookie_test.go 2014-03-19 20:20:19 +0000 | 345 | func TestClientTrailers(t *testing.T) { |
2764 | 346 | +++ http13client/cookie_test.go 2014-03-19 22:27:37 +0000 | 346 | defer afterTest(t) |
2765 | 347 | @@ -9,6 +9,7 @@ | 347 | - ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) { |
2766 | 348 | "encoding/json" | 348 | + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
2767 | 349 | "fmt" | 349 | w.Header().Set("Connection", "close") |
2768 | 350 | "log" | 350 | w.Header().Set("Trailer", "Server-Trailer-A, Server-Trailer-B") |
2769 | 351 | + "net/http" | 351 | w.Header().Add("Trailer", "Server-Trailer-C") |
2770 | 352 | "os" | 352 | @@ -992,9 +925,9 @@ |
2771 | 353 | "reflect" | 353 | // trailers to be sent, if and only if they were |
2772 | 354 | "strings" | 354 | // previously declared with w.Header().Set("Trailer", |
2773 | 355 | @@ -17,39 +18,39 @@ | 355 | // ..keys..) |
2774 | 356 | ) | 356 | - w.(Flusher).Flush() |
2775 | 357 | 357 | - conn, buf, _ := w.(Hijacker).Hijack() | |
2776 | 358 | var writeSetCookiesTests = []struct { | 358 | - t := Header{} |
2777 | 359 | - Cookie *Cookie | 359 | + w.(http.Flusher).Flush() |
2778 | 360 | + Cookie *http.Cookie | 360 | + conn, buf, _ := w.(http.Hijacker).Hijack() |
2779 | 361 | Raw string | 361 | + t := http.Header{} |
2780 | 362 | }{ | 362 | t.Set("Server-Trailer-A", "valuea") |
2781 | 363 | { | 363 | t.Set("Server-Trailer-C", "valuec") // skipping B |
2782 | 364 | - &Cookie{Name: "cookie-1", Value: "v$1"}, | 364 | buf.WriteString("0\r\n") // eof |
2783 | 365 | + &http.Cookie{Name: "cookie-1", Value: "v$1"}, | 365 | @@ -1015,7 +948,7 @@ |
2784 | 366 | "cookie-1=v$1", | 366 | req.Trailer["Client-Trailer-B"] = []string{"valueb"} |
2785 | 367 | }, | 367 | }), |
2786 | 368 | { | 368 | )) |
2787 | 369 | - &Cookie{Name: "cookie-2", Value: "two", MaxAge: 3600}, | 369 | - req.Trailer = Header{ |
2788 | 370 | + &http.Cookie{Name: "cookie-2", Value: "two", MaxAge: 3600}, | 370 | + req.Trailer = http.Header{ |
2789 | 371 | "cookie-2=two; Max-Age=3600", | 371 | "Client-Trailer-A": nil, // to be set later |
2790 | 372 | }, | 372 | "Client-Trailer-B": nil, // to be set later |
2791 | 373 | { | 373 | } |
2792 | 374 | - &Cookie{Name: "cookie-3", Value: "three", Domain: ".example.com"}, | 374 | @@ -1027,7 +960,7 @@ |
2793 | 375 | + &http.Cookie{Name: "cookie-3", Value: "three", Domain: ".example.com"}, | 375 | if err := wantBody(res, err, "decl: [Client-Trailer-A Client-Trailer-B], vals: valuea, valueb"); err != nil { |
2794 | 376 | "cookie-3=three; Domain=example.com", | 376 | t.Error(err) |
2795 | 377 | }, | 377 | } |
2796 | 378 | { | 378 | - want := Header{ |
2797 | 379 | - &Cookie{Name: "cookie-4", Value: "four", Path: "/restricted/"}, | 379 | + want := http.Header{ |
2798 | 380 | + &http.Cookie{Name: "cookie-4", Value: "four", Path: "/restricted/"}, | 380 | "Server-Trailer-A": []string{"valuea"}, |
2799 | 381 | "cookie-4=four; Path=/restricted/", | 381 | "Server-Trailer-B": nil, |
2800 | 382 | }, | 382 | "Server-Trailer-C": []string{"valuec"}, |
2578 | 383 | { | ||
2579 | 384 | - &Cookie{Name: "cookie-5", Value: "five", Domain: "wrong;bad.abc"}, | ||
2580 | 385 | + &http.Cookie{Name: "cookie-5", Value: "five", Domain: "wrong;bad.abc"}, | ||
2581 | 386 | "cookie-5=five", | ||
2582 | 387 | }, | ||
2583 | 388 | { | ||
2584 | 389 | - &Cookie{Name: "cookie-6", Value: "six", Domain: "bad-.abc"}, | ||
2585 | 390 | + &http.Cookie{Name: "cookie-6", Value: "six", Domain: "bad-.abc"}, | ||
2586 | 391 | "cookie-6=six", | ||
2587 | 392 | }, | ||
2588 | 393 | { | ||
2589 | 394 | - &Cookie{Name: "cookie-7", Value: "seven", Domain: "127.0.0.1"}, | ||
2590 | 395 | + &http.Cookie{Name: "cookie-7", Value: "seven", Domain: "127.0.0.1"}, | ||
2591 | 396 | "cookie-7=seven; Domain=127.0.0.1", | ||
2592 | 397 | }, | ||
2593 | 398 | { | ||
2594 | 399 | - &Cookie{Name: "cookie-8", Value: "eight", Domain: "::1"}, | ||
2595 | 400 | + &http.Cookie{Name: "cookie-8", Value: "eight", Domain: "::1"}, | ||
2596 | 401 | "cookie-8=eight", | ||
2597 | 402 | }, | ||
2598 | 403 | } | ||
2599 | 404 | @@ -71,10 +72,10 @@ | ||
2600 | 405 | } | ||
2601 | 406 | } | ||
2602 | 407 | |||
2603 | 408 | -type headerOnlyResponseWriter Header | ||
2604 | 409 | +type headerOnlyResponseWriter http.Header | ||
2605 | 410 | |||
2606 | 411 | -func (ho headerOnlyResponseWriter) Header() Header { | ||
2607 | 412 | - return Header(ho) | ||
2608 | 413 | +func (ho headerOnlyResponseWriter) Header() http.Header { | ||
2609 | 414 | + return http.Header(ho) | ||
2610 | 415 | } | ||
2611 | 416 | |||
2612 | 417 | func (ho headerOnlyResponseWriter) Write([]byte) (int, error) { | ||
2613 | 418 | @@ -86,9 +87,9 @@ | ||
2614 | 419 | } | ||
2615 | 420 | |||
2616 | 421 | func TestSetCookie(t *testing.T) { | ||
2617 | 422 | - m := make(Header) | ||
2618 | 423 | - SetCookie(headerOnlyResponseWriter(m), &Cookie{Name: "cookie-1", Value: "one", Path: "/restricted/"}) | ||
2619 | 424 | - SetCookie(headerOnlyResponseWriter(m), &Cookie{Name: "cookie-2", Value: "two", MaxAge: 3600}) | ||
2620 | 425 | + m := make(http.Header) | ||
2621 | 426 | + http.SetCookie(headerOnlyResponseWriter(m), &http.Cookie{Name: "cookie-1", Value: "one", Path: "/restricted/"}) | ||
2622 | 427 | + http.SetCookie(headerOnlyResponseWriter(m), &http.Cookie{Name: "cookie-2", Value: "two", MaxAge: 3600}) | ||
2623 | 428 | if l := len(m["Set-Cookie"]); l != 2 { | ||
2624 | 429 | t.Fatalf("expected %d cookies, got %d", 2, l) | ||
2625 | 430 | } | ||
2626 | 431 | @@ -101,19 +102,19 @@ | ||
2627 | 432 | } | ||
2628 | 433 | |||
2629 | 434 | var addCookieTests = []struct { | ||
2630 | 435 | - Cookies []*Cookie | ||
2631 | 436 | + Cookies []*http.Cookie | ||
2632 | 437 | Raw string | ||
2633 | 438 | }{ | ||
2634 | 439 | { | ||
2635 | 440 | - []*Cookie{}, | ||
2636 | 441 | + []*http.Cookie{}, | ||
2637 | 442 | "", | ||
2638 | 443 | }, | ||
2639 | 444 | { | ||
2640 | 445 | - []*Cookie{{Name: "cookie-1", Value: "v$1"}}, | ||
2641 | 446 | + []*http.Cookie{{Name: "cookie-1", Value: "v$1"}}, | ||
2642 | 447 | "cookie-1=v$1", | ||
2643 | 448 | }, | ||
2644 | 449 | { | ||
2645 | 450 | - []*Cookie{ | ||
2646 | 451 | + []*http.Cookie{ | ||
2647 | 452 | {Name: "cookie-1", Value: "v$1"}, | ||
2648 | 453 | {Name: "cookie-2", Value: "v$2"}, | ||
2649 | 454 | {Name: "cookie-3", Value: "v$3"}, | ||
2650 | 455 | @@ -136,16 +137,16 @@ | ||
2651 | 456 | } | ||
2652 | 457 | |||
2653 | 458 | var readSetCookiesTests = []struct { | ||
2654 | 459 | - Header Header | ||
2655 | 460 | - Cookies []*Cookie | ||
2656 | 461 | + Header http.Header | ||
2657 | 462 | + Cookies []*http.Cookie | ||
2658 | 463 | }{ | ||
2659 | 464 | { | ||
2660 | 465 | - Header{"Set-Cookie": {"Cookie-1=v$1"}}, | ||
2661 | 466 | - []*Cookie{{Name: "Cookie-1", Value: "v$1", Raw: "Cookie-1=v$1"}}, | ||
2662 | 467 | + http.Header{"Set-Cookie": {"Cookie-1=v$1"}}, | ||
2663 | 468 | + []*http.Cookie{{Name: "Cookie-1", Value: "v$1", Raw: "Cookie-1=v$1"}}, | ||
2664 | 469 | }, | ||
2665 | 470 | { | ||
2666 | 471 | - Header{"Set-Cookie": {"NID=99=YsDT5i3E-CXax-; expires=Wed, 23-Nov-2011 01:05:03 GMT; path=/; domain=.google.ch; HttpOnly"}}, | ||
2667 | 472 | - []*Cookie{{ | ||
2668 | 473 | + http.Header{"Set-Cookie": {"NID=99=YsDT5i3E-CXax-; expires=Wed, 23-Nov-2011 01:05:03 GMT; path=/; domain=.google.ch; HttpOnly"}}, | ||
2669 | 474 | + []*http.Cookie{{ | ||
2670 | 475 | Name: "NID", | ||
2671 | 476 | Value: "99=YsDT5i3E-CXax-", | ||
2672 | 477 | Path: "/", | ||
2673 | 478 | @@ -157,8 +158,8 @@ | ||
2674 | 479 | }}, | ||
2675 | 480 | }, | ||
2676 | 481 | { | ||
2677 | 482 | - Header{"Set-Cookie": {".ASPXAUTH=7E3AA; expires=Wed, 07-Mar-2012 14:25:06 GMT; path=/; HttpOnly"}}, | ||
2678 | 483 | - []*Cookie{{ | ||
2679 | 484 | + http.Header{"Set-Cookie": {".ASPXAUTH=7E3AA; expires=Wed, 07-Mar-2012 14:25:06 GMT; path=/; HttpOnly"}}, | ||
2680 | 485 | + []*http.Cookie{{ | ||
2681 | 486 | Name: ".ASPXAUTH", | ||
2682 | 487 | Value: "7E3AA", | ||
2683 | 488 | Path: "/", | ||
2684 | 489 | @@ -169,8 +170,8 @@ | ||
2685 | 490 | }}, | ||
2686 | 491 | }, | ||
2687 | 492 | { | ||
2688 | 493 | - Header{"Set-Cookie": {"ASP.NET_SessionId=foo; path=/; HttpOnly"}}, | ||
2689 | 494 | - []*Cookie{{ | ||
2690 | 495 | + http.Header{"Set-Cookie": {"ASP.NET_SessionId=foo; path=/; HttpOnly"}}, | ||
2691 | 496 | + []*http.Cookie{{ | ||
2692 | 497 | Name: "ASP.NET_SessionId", | ||
2693 | 498 | Value: "foo", | ||
2694 | 499 | Path: "/", | ||
2695 | 500 | @@ -207,37 +208,37 @@ | ||
2696 | 501 | } | ||
2697 | 502 | |||
2698 | 503 | var readCookiesTests = []struct { | ||
2699 | 504 | - Header Header | ||
2700 | 505 | + Header http.Header | ||
2701 | 506 | Filter string | ||
2702 | 507 | - Cookies []*Cookie | ||
2703 | 508 | + Cookies []*http.Cookie | ||
2704 | 509 | }{ | ||
2705 | 510 | { | ||
2706 | 511 | - Header{"Cookie": {"Cookie-1=v$1", "c2=v2"}}, | ||
2707 | 512 | - "", | ||
2708 | 513 | - []*Cookie{ | ||
2709 | 514 | - {Name: "Cookie-1", Value: "v$1"}, | ||
2710 | 515 | - {Name: "c2", Value: "v2"}, | ||
2711 | 516 | - }, | ||
2712 | 517 | - }, | ||
2713 | 518 | - { | ||
2714 | 519 | - Header{"Cookie": {"Cookie-1=v$1", "c2=v2"}}, | ||
2715 | 520 | - "c2", | ||
2716 | 521 | - []*Cookie{ | ||
2717 | 522 | - {Name: "c2", Value: "v2"}, | ||
2718 | 523 | - }, | ||
2719 | 524 | - }, | ||
2720 | 525 | - { | ||
2721 | 526 | - Header{"Cookie": {"Cookie-1=v$1; c2=v2"}}, | ||
2722 | 527 | - "", | ||
2723 | 528 | - []*Cookie{ | ||
2724 | 529 | - {Name: "Cookie-1", Value: "v$1"}, | ||
2725 | 530 | - {Name: "c2", Value: "v2"}, | ||
2726 | 531 | - }, | ||
2727 | 532 | - }, | ||
2728 | 533 | - { | ||
2729 | 534 | - Header{"Cookie": {"Cookie-1=v$1; c2=v2"}}, | ||
2730 | 535 | - "c2", | ||
2731 | 536 | - []*Cookie{ | ||
2732 | 537 | + http.Header{"Cookie": {"Cookie-1=v$1", "c2=v2"}}, | ||
2733 | 538 | + "", | ||
2734 | 539 | + []*http.Cookie{ | ||
2735 | 540 | + {Name: "Cookie-1", Value: "v$1"}, | ||
2736 | 541 | + {Name: "c2", Value: "v2"}, | ||
2737 | 542 | + }, | ||
2738 | 543 | + }, | ||
2739 | 544 | + { | ||
2740 | 545 | + http.Header{"Cookie": {"Cookie-1=v$1", "c2=v2"}}, | ||
2741 | 546 | + "c2", | ||
2742 | 547 | + []*http.Cookie{ | ||
2743 | 548 | + {Name: "c2", Value: "v2"}, | ||
2744 | 549 | + }, | ||
2745 | 550 | + }, | ||
2746 | 551 | + { | ||
2747 | 552 | + http.Header{"Cookie": {"Cookie-1=v$1; c2=v2"}}, | ||
2748 | 553 | + "", | ||
2749 | 554 | + []*http.Cookie{ | ||
2750 | 555 | + {Name: "Cookie-1", Value: "v$1"}, | ||
2751 | 556 | + {Name: "c2", Value: "v2"}, | ||
2752 | 557 | + }, | ||
2753 | 558 | + }, | ||
2754 | 559 | + { | ||
2755 | 560 | + http.Header{"Cookie": {"Cookie-1=v$1; c2=v2"}}, | ||
2756 | 561 | + "c2", | ||
2757 | 562 | + []*http.Cookie{ | ||
2758 | 563 | {Name: "c2", Value: "v2"}, | ||
2759 | 564 | }, | ||
2760 | 565 | }, | ||
2801 | 566 | 383 | ||
2802 | 567 | === modified file 'http13client/export_test.go' | 384 | === modified file 'http13client/export_test.go' |
2805 | 568 | --- http13client/export_test.go 2014-03-19 20:20:19 +0000 | 385 | --- http13client/export_test.go 2014-06-20 11:00:47 +0000 |
2806 | 569 | +++ http13client/export_test.go 2014-03-19 22:27:37 +0000 | 386 | +++ http13client/export_test.go 2014-06-20 12:00:22 +0000 |
2807 | 570 | @@ -9,15 +9,12 @@ | 387 | @@ -9,15 +9,12 @@ |
2808 | 571 | 388 | ||
2809 | 572 | import ( | 389 | import ( |
2810 | @@ -599,8 +416,8 @@ | |||
2811 | 599 | noProxyEnv.reset() | 416 | noProxyEnv.reset() |
2812 | 600 | 417 | ||
2813 | 601 | === modified file 'http13client/header_test.go' | 418 | === modified file 'http13client/header_test.go' |
2816 | 602 | --- http13client/header_test.go 2014-03-19 20:20:19 +0000 | 419 | --- http13client/header_test.go 2014-06-20 11:00:47 +0000 |
2817 | 603 | +++ http13client/header_test.go 2014-03-19 22:27:37 +0000 | 420 | +++ http13client/header_test.go 2014-06-20 12:00:22 +0000 |
2818 | 604 | @@ -6,19 +6,20 @@ | 421 | @@ -6,19 +6,20 @@ |
2819 | 605 | 422 | ||
2820 | 606 | import ( | 423 | import ( |
2821 | @@ -731,8 +548,8 @@ | |||
2822 | 731 | } | 548 | } |
2823 | 732 | 549 | ||
2824 | 733 | === modified file 'http13client/npn_test.go' | 550 | === modified file 'http13client/npn_test.go' |
2827 | 734 | --- http13client/npn_test.go 2014-03-19 21:38:56 +0000 | 551 | --- http13client/npn_test.go 2014-06-20 11:00:47 +0000 |
2828 | 735 | +++ http13client/npn_test.go 2014-03-19 22:27:37 +0000 | 552 | +++ http13client/npn_test.go 2014-06-20 12:05:53 +0000 |
2829 | 736 | @@ -11,13 +11,14 @@ | 553 | @@ -11,13 +11,14 @@ |
2830 | 737 | "io" | 554 | "io" |
2831 | 738 | "io/ioutil" | 555 | "io/ioutil" |
2832 | @@ -792,8 +609,8 @@ | |||
2833 | 792 | func (w http09Writer) WriteHeader(int) {} // no headers | 609 | func (w http09Writer) WriteHeader(int) {} // no headers |
2834 | 793 | 610 | ||
2835 | 794 | === modified file 'http13client/readrequest_test.go' | 611 | === modified file 'http13client/readrequest_test.go' |
2838 | 795 | --- http13client/readrequest_test.go 2014-03-19 20:20:19 +0000 | 612 | --- http13client/readrequest_test.go 2014-06-20 11:00:47 +0000 |
2839 | 796 | +++ http13client/readrequest_test.go 2014-03-19 22:27:37 +0000 | 613 | +++ http13client/readrequest_test.go 2014-06-20 12:00:22 +0000 |
2840 | 797 | @@ -9,6 +9,7 @@ | 614 | @@ -9,6 +9,7 @@ |
2841 | 798 | "bytes" | 615 | "bytes" |
2842 | 799 | "fmt" | 616 | "fmt" |
2843 | @@ -909,8 +726,8 @@ | |||
2844 | 909 | Close: false, | 726 | Close: false, |
2845 | 910 | 727 | ||
2846 | 911 | === modified file 'http13client/request_test.go' | 728 | === modified file 'http13client/request_test.go' |
2849 | 912 | --- http13client/request_test.go 2014-03-19 21:38:56 +0000 | 729 | --- http13client/request_test.go 2014-06-20 11:00:47 +0000 |
2850 | 913 | +++ http13client/request_test.go 2014-03-19 22:27:37 +0000 | 730 | +++ http13client/request_test.go 2014-06-20 12:05:53 +0000 |
2851 | 914 | @@ -12,6 +12,7 @@ | 731 | @@ -12,6 +12,7 @@ |
2852 | 915 | "io/ioutil" | 732 | "io/ioutil" |
2853 | 916 | "mime/multipart" | 733 | "mime/multipart" |
2854 | @@ -945,8 +762,26 @@ | |||
2855 | 945 | + req.Header = http.Header{"Content-Type": {"text/plain"}} | 762 | + req.Header = http.Header{"Content-Type": {"text/plain"}} |
2856 | 946 | multipart, err = req.MultipartReader() | 763 | multipart, err = req.MultipartReader() |
2857 | 947 | if multipart != nil { | 764 | if multipart != nil { |
2860 | 948 | t.Errorf("unexpected multipart for text/plain") | 765 | t.Error("unexpected multipart for text/plain") |
2861 | 949 | @@ -159,7 +160,7 @@ | 766 | @@ -161,7 +162,7 @@ |
2862 | 767 | func TestParseMultipartForm(t *testing.T) { | ||
2863 | 768 | req := &Request{ | ||
2864 | 769 | Method: "POST", | ||
2865 | 770 | - Header: Header{"Content-Type": {`multipart/form-data; boundary="foo123"`}}, | ||
2866 | 771 | + Header: http.Header{"Content-Type": {`multipart/form-data; boundary="foo123"`}}, | ||
2867 | 772 | Body: ioutil.NopCloser(new(bytes.Buffer)), | ||
2868 | 773 | } | ||
2869 | 774 | err := req.ParseMultipartForm(25) | ||
2870 | 775 | @@ -169,7 +170,7 @@ | ||
2871 | 776 | t.Error("expected multipart EOF, got nil") | ||
2872 | 777 | } | ||
2873 | 778 | |||
2874 | 779 | - req.Header = Header{"Content-Type": {"text/plain"}} | ||
2875 | 780 | + req.Header = http.Header{"Content-Type": {"text/plain"}} | ||
2876 | 781 | err = req.ParseMultipartForm(25) | ||
2877 | 782 | if err != ErrNotMultipart { | ||
2878 | 783 | t.Error("expected ErrNotMultipart for text/plain") | ||
2879 | 784 | @@ -177,7 +178,7 @@ | ||
2880 | 950 | } | 785 | } |
2881 | 951 | 786 | ||
2882 | 952 | func TestRedirect(t *testing.T) { | 787 | func TestRedirect(t *testing.T) { |
2883 | @@ -957,8 +792,8 @@ | |||
2884 | 957 | w.Header().Set("Location", "/foo/") | 792 | w.Header().Set("Location", "/foo/") |
2885 | 958 | 793 | ||
2886 | 959 | === modified file 'http13client/requestwrite_test.go' | 794 | === modified file 'http13client/requestwrite_test.go' |
2889 | 960 | --- http13client/requestwrite_test.go 2014-03-19 20:20:19 +0000 | 795 | --- http13client/requestwrite_test.go 2014-06-20 11:00:47 +0000 |
2890 | 961 | +++ http13client/requestwrite_test.go 2014-03-19 22:27:37 +0000 | 796 | +++ http13client/requestwrite_test.go 2014-06-20 12:00:22 +0000 |
2891 | 962 | @@ -10,6 +10,7 @@ | 797 | @@ -10,6 +10,7 @@ |
2892 | 963 | "fmt" | 798 | "fmt" |
2893 | 964 | "io" | 799 | "io" |
2894 | @@ -1068,8 +903,8 @@ | |||
2895 | 1068 | var braw bytes.Buffer | 903 | var braw bytes.Buffer |
2896 | 1069 | 904 | ||
2897 | 1070 | === modified file 'http13client/response_test.go' | 905 | === modified file 'http13client/response_test.go' |
2900 | 1071 | --- http13client/response_test.go 2014-03-19 20:20:19 +0000 | 906 | --- http13client/response_test.go 2014-06-20 11:00:47 +0000 |
2901 | 1072 | +++ http13client/response_test.go 2014-03-19 22:27:37 +0000 | 907 | +++ http13client/response_test.go 2014-06-20 12:05:53 +0000 |
2902 | 1073 | @@ -12,6 +12,7 @@ | 908 | @@ -12,6 +12,7 @@ |
2903 | 1074 | "fmt" | 909 | "fmt" |
2904 | 1075 | "io" | 910 | "io" |
2905 | @@ -1078,7 +913,7 @@ | |||
2906 | 1078 | "net/url" | 913 | "net/url" |
2907 | 1079 | "reflect" | 914 | "reflect" |
2908 | 1080 | "regexp" | 915 | "regexp" |
2910 | 1081 | @@ -44,7 +45,7 @@ | 916 | @@ -48,7 +49,7 @@ |
2911 | 1082 | ProtoMajor: 1, | 917 | ProtoMajor: 1, |
2912 | 1083 | ProtoMinor: 0, | 918 | ProtoMinor: 0, |
2913 | 1084 | Request: dummyReq("GET"), | 919 | Request: dummyReq("GET"), |
2914 | @@ -1087,7 +922,7 @@ | |||
2915 | 1087 | "Connection": {"close"}, // TODO(rsc): Delete? | 922 | "Connection": {"close"}, // TODO(rsc): Delete? |
2916 | 1088 | }, | 923 | }, |
2917 | 1089 | Close: true, | 924 | Close: true, |
2919 | 1090 | @@ -67,7 +68,7 @@ | 925 | @@ -71,7 +72,7 @@ |
2920 | 1091 | Proto: "HTTP/1.1", | 926 | Proto: "HTTP/1.1", |
2921 | 1092 | ProtoMajor: 1, | 927 | ProtoMajor: 1, |
2922 | 1093 | ProtoMinor: 1, | 928 | ProtoMinor: 1, |
2923 | @@ -1096,7 +931,7 @@ | |||
2924 | 1096 | Request: dummyReq("GET"), | 931 | Request: dummyReq("GET"), |
2925 | 1097 | Close: true, | 932 | Close: true, |
2926 | 1098 | ContentLength: -1, | 933 | ContentLength: -1, |
2928 | 1099 | @@ -88,7 +89,7 @@ | 934 | @@ -92,7 +93,7 @@ |
2929 | 1100 | Proto: "HTTP/1.1", | 935 | Proto: "HTTP/1.1", |
2930 | 1101 | ProtoMajor: 1, | 936 | ProtoMajor: 1, |
2931 | 1102 | ProtoMinor: 1, | 937 | ProtoMinor: 1, |
2932 | @@ -1105,7 +940,7 @@ | |||
2933 | 1105 | Request: dummyReq("GET"), | 940 | Request: dummyReq("GET"), |
2934 | 1106 | Close: false, | 941 | Close: false, |
2935 | 1107 | ContentLength: 0, | 942 | ContentLength: 0, |
2937 | 1108 | @@ -112,7 +113,7 @@ | 943 | @@ -116,7 +117,7 @@ |
2938 | 1109 | ProtoMajor: 1, | 944 | ProtoMajor: 1, |
2939 | 1110 | ProtoMinor: 0, | 945 | ProtoMinor: 0, |
2940 | 1111 | Request: dummyReq("GET"), | 946 | Request: dummyReq("GET"), |
2941 | @@ -1114,61 +949,61 @@ | |||
2942 | 1114 | "Connection": {"close"}, | 949 | "Connection": {"close"}, |
2943 | 1115 | "Content-Length": {"10"}, | 950 | "Content-Length": {"10"}, |
2944 | 1116 | }, | 951 | }, |
3000 | 1117 | @@ -142,7 +143,7 @@ | 952 | @@ -146,7 +147,7 @@ |
3001 | 1118 | ProtoMajor: 1, | 953 | ProtoMajor: 1, |
3002 | 1119 | ProtoMinor: 1, | 954 | ProtoMinor: 1, |
3003 | 1120 | Request: dummyReq("GET"), | 955 | Request: dummyReq("GET"), |
3004 | 1121 | - Header: Header{}, | 956 | - Header: Header{}, |
3005 | 1122 | + Header: http.Header{}, | 957 | + Header: http.Header{}, |
3006 | 1123 | Close: false, | 958 | Close: false, |
3007 | 1124 | ContentLength: -1, | 959 | ContentLength: -1, |
3008 | 1125 | TransferEncoding: []string{"chunked"}, | 960 | TransferEncoding: []string{"chunked"}, |
3009 | 1126 | @@ -169,7 +170,7 @@ | 961 | @@ -173,7 +174,7 @@ |
3010 | 1127 | ProtoMajor: 1, | 962 | ProtoMajor: 1, |
3011 | 1128 | ProtoMinor: 1, | 963 | ProtoMinor: 1, |
3012 | 1129 | Request: dummyReq("GET"), | 964 | Request: dummyReq("GET"), |
3013 | 1130 | - Header: Header{}, | 965 | - Header: Header{}, |
3014 | 1131 | + Header: http.Header{}, | 966 | + Header: http.Header{}, |
3015 | 1132 | Close: false, | 967 | Close: false, |
3016 | 1133 | ContentLength: -1, | 968 | ContentLength: -1, |
3017 | 1134 | TransferEncoding: []string{"chunked"}, | 969 | TransferEncoding: []string{"chunked"}, |
3018 | 1135 | @@ -191,7 +192,7 @@ | 970 | @@ -195,7 +196,7 @@ |
3019 | 1136 | ProtoMajor: 1, | 971 | ProtoMajor: 1, |
3020 | 1137 | ProtoMinor: 1, | 972 | ProtoMinor: 1, |
3021 | 1138 | Request: dummyReq("HEAD"), | 973 | Request: dummyReq("HEAD"), |
3022 | 1139 | - Header: Header{}, | 974 | - Header: Header{}, |
3023 | 1140 | + Header: http.Header{}, | 975 | + Header: http.Header{}, |
3024 | 1141 | TransferEncoding: []string{"chunked"}, | 976 | TransferEncoding: []string{"chunked"}, |
3025 | 1142 | Close: false, | 977 | Close: false, |
3026 | 1143 | ContentLength: -1, | 978 | ContentLength: -1, |
3027 | 1144 | @@ -213,7 +214,7 @@ | 979 | @@ -217,7 +218,7 @@ |
3028 | 1145 | ProtoMajor: 1, | 980 | ProtoMajor: 1, |
3029 | 1146 | ProtoMinor: 0, | 981 | ProtoMinor: 0, |
3030 | 1147 | Request: dummyReq("HEAD"), | 982 | Request: dummyReq("HEAD"), |
3031 | 1148 | - Header: Header{"Content-Length": {"256"}}, | 983 | - Header: Header{"Content-Length": {"256"}}, |
3032 | 1149 | + Header: http.Header{"Content-Length": {"256"}}, | 984 | + Header: http.Header{"Content-Length": {"256"}}, |
3033 | 1150 | TransferEncoding: nil, | 985 | TransferEncoding: nil, |
3034 | 1151 | Close: true, | 986 | Close: true, |
3035 | 1152 | ContentLength: 256, | 987 | ContentLength: 256, |
3036 | 1153 | @@ -235,7 +236,7 @@ | 988 | @@ -239,7 +240,7 @@ |
3037 | 1154 | ProtoMajor: 1, | 989 | ProtoMajor: 1, |
3038 | 1155 | ProtoMinor: 1, | 990 | ProtoMinor: 1, |
3039 | 1156 | Request: dummyReq("HEAD"), | 991 | Request: dummyReq("HEAD"), |
3040 | 1157 | - Header: Header{"Content-Length": {"256"}}, | 992 | - Header: Header{"Content-Length": {"256"}}, |
3041 | 1158 | + Header: http.Header{"Content-Length": {"256"}}, | 993 | + Header: http.Header{"Content-Length": {"256"}}, |
3042 | 1159 | TransferEncoding: nil, | 994 | TransferEncoding: nil, |
3043 | 1160 | Close: false, | 995 | Close: false, |
3044 | 1161 | ContentLength: 256, | 996 | ContentLength: 256, |
3045 | 1162 | @@ -256,7 +257,7 @@ | 997 | @@ -260,7 +261,7 @@ |
3046 | 1163 | ProtoMajor: 1, | 998 | ProtoMajor: 1, |
3047 | 1164 | ProtoMinor: 0, | 999 | ProtoMinor: 0, |
3048 | 1165 | Request: dummyReq("HEAD"), | 1000 | Request: dummyReq("HEAD"), |
3049 | 1166 | - Header: Header{}, | 1001 | - Header: Header{}, |
3050 | 1167 | + Header: http.Header{}, | 1002 | + Header: http.Header{}, |
3051 | 1168 | TransferEncoding: nil, | 1003 | TransferEncoding: nil, |
3052 | 1169 | Close: true, | 1004 | Close: true, |
3053 | 1170 | ContentLength: -1, | 1005 | ContentLength: -1, |
3054 | 1171 | @@ -278,7 +279,7 @@ | 1006 | @@ -282,7 +283,7 @@ |
3055 | 1172 | ProtoMajor: 1, | 1007 | ProtoMajor: 1, |
3056 | 1173 | ProtoMinor: 1, | 1008 | ProtoMinor: 1, |
3057 | 1174 | Request: dummyReq("GET"), | 1009 | Request: dummyReq("GET"), |
3058 | @@ -1177,25 +1012,25 @@ | |||
3059 | 1177 | "Content-Length": {"0"}, | 1012 | "Content-Length": {"0"}, |
3060 | 1178 | }, | 1013 | }, |
3061 | 1179 | Close: false, | 1014 | Close: false, |
3081 | 1180 | @@ -299,7 +300,7 @@ | 1015 | @@ -303,7 +304,7 @@ |
3082 | 1181 | ProtoMajor: 1, | 1016 | ProtoMajor: 1, |
3083 | 1182 | ProtoMinor: 0, | 1017 | ProtoMinor: 0, |
3084 | 1183 | Request: dummyReq("GET"), | 1018 | Request: dummyReq("GET"), |
3085 | 1184 | - Header: Header{}, | 1019 | - Header: Header{}, |
3086 | 1185 | + Header: http.Header{}, | 1020 | + Header: http.Header{}, |
3087 | 1186 | Close: true, | 1021 | Close: true, |
3088 | 1187 | ContentLength: -1, | 1022 | ContentLength: -1, |
3089 | 1188 | }, | 1023 | }, |
3090 | 1189 | @@ -318,7 +319,7 @@ | 1024 | @@ -322,7 +323,7 @@ |
3091 | 1190 | ProtoMajor: 1, | 1025 | ProtoMajor: 1, |
3092 | 1191 | ProtoMinor: 0, | 1026 | ProtoMinor: 0, |
3093 | 1192 | Request: dummyReq("GET"), | 1027 | Request: dummyReq("GET"), |
3094 | 1193 | - Header: Header{}, | 1028 | - Header: Header{}, |
3095 | 1194 | + Header: http.Header{}, | 1029 | + Header: http.Header{}, |
3096 | 1195 | Close: true, | 1030 | Close: true, |
3097 | 1196 | ContentLength: -1, | 1031 | ContentLength: -1, |
3098 | 1197 | }, | 1032 | }, |
3099 | 1198 | @@ -340,7 +341,7 @@ | 1033 | @@ -344,7 +345,7 @@ |
3100 | 1199 | ProtoMajor: 1, | 1034 | ProtoMajor: 1, |
3101 | 1200 | ProtoMinor: 1, | 1035 | ProtoMinor: 1, |
3102 | 1201 | Request: dummyReq("GET"), | 1036 | Request: dummyReq("GET"), |
3103 | @@ -1204,7 +1039,7 @@ | |||
3104 | 1204 | "Content-Type": []string{"multipart/byteranges; boundary=18a75608c8f47cef"}, | 1039 | "Content-Type": []string{"multipart/byteranges; boundary=18a75608c8f47cef"}, |
3105 | 1205 | }, | 1040 | }, |
3106 | 1206 | Close: true, | 1041 | Close: true, |
3108 | 1207 | @@ -363,7 +364,7 @@ | 1042 | @@ -367,7 +368,7 @@ |
3109 | 1208 | Proto: "HTTP/1.0", | 1043 | Proto: "HTTP/1.0", |
3110 | 1209 | ProtoMajor: 1, | 1044 | ProtoMajor: 1, |
3111 | 1210 | ProtoMinor: 0, | 1045 | ProtoMinor: 0, |
3112 | @@ -1213,7 +1048,7 @@ | |||
3113 | 1213 | "Connection": {"close"}, // TODO(rsc): Delete? | 1048 | "Connection": {"close"}, // TODO(rsc): Delete? |
3114 | 1214 | }, | 1049 | }, |
3115 | 1215 | Close: true, | 1050 | Close: true, |
3117 | 1216 | @@ -545,7 +546,7 @@ | 1051 | @@ -549,7 +550,7 @@ |
3118 | 1217 | func TestLocationResponse(t *testing.T) { | 1052 | func TestLocationResponse(t *testing.T) { |
3119 | 1218 | for i, tt := range responseLocationTests { | 1053 | for i, tt := range responseLocationTests { |
3120 | 1219 | res := new(Response) | 1054 | res := new(Response) |
3121 | @@ -1222,7 +1057,7 @@ | |||
3122 | 1222 | res.Header.Set("Location", tt.location) | 1057 | res.Header.Set("Location", tt.location) |
3123 | 1223 | if tt.requrl != "" { | 1058 | if tt.requrl != "" { |
3124 | 1224 | res.Request = &Request{} | 1059 | res.Request = &Request{} |
3126 | 1225 | @@ -626,16 +627,3 @@ | 1060 | @@ -630,16 +631,3 @@ |
3127 | 1226 | t.Errorf("ReadResponse = %v; want io.ErrUnexpectedEOF", err) | 1061 | t.Errorf("ReadResponse = %v; want io.ErrUnexpectedEOF", err) |
3128 | 1227 | } | 1062 | } |
3129 | 1228 | } | 1063 | } |
3130 | @@ -1241,8 +1076,8 @@ | |||
3131 | 1241 | -} | 1076 | -} |
3132 | 1242 | 1077 | ||
3133 | 1243 | === modified file 'http13client/responsewrite_test.go' | 1078 | === modified file 'http13client/responsewrite_test.go' |
3136 | 1244 | --- http13client/responsewrite_test.go 2014-03-19 20:20:19 +0000 | 1079 | --- http13client/responsewrite_test.go 2014-06-20 11:00:47 +0000 |
3137 | 1245 | +++ http13client/responsewrite_test.go 2014-03-19 22:27:37 +0000 | 1080 | +++ http13client/responsewrite_test.go 2014-06-20 12:05:53 +0000 |
3138 | 1246 | @@ -7,6 +7,7 @@ | 1081 | @@ -7,6 +7,7 @@ |
3139 | 1247 | import ( | 1082 | import ( |
3140 | 1248 | "bytes" | 1083 | "bytes" |
3141 | @@ -1257,7 +1092,7 @@ | |||
3142 | 1257 | Request: dummyReq("GET"), | 1092 | Request: dummyReq("GET"), |
3143 | 1258 | - Header: Header{}, | 1093 | - Header: Header{}, |
3144 | 1259 | + Header: http.Header{}, | 1094 | + Header: http.Header{}, |
3146 | 1260 | Body: ioutil.NopCloser(bytes.NewBufferString("abcdef")), | 1095 | Body: ioutil.NopCloser(strings.NewReader("abcdef")), |
3147 | 1261 | ContentLength: 6, | 1096 | ContentLength: 6, |
3148 | 1262 | }, | 1097 | }, |
3149 | 1263 | @@ -41,7 +42,7 @@ | 1098 | @@ -41,7 +42,7 @@ |
3150 | @@ -1270,6 +1105,60 @@ | |||
3151 | 1270 | ContentLength: -1, | 1105 | ContentLength: -1, |
3152 | 1271 | }, | 1106 | }, |
3153 | 1272 | @@ -56,7 +57,7 @@ | 1107 | @@ -56,7 +57,7 @@ |
3154 | 1108 | ProtoMajor: 1, | ||
3155 | 1109 | ProtoMinor: 1, | ||
3156 | 1110 | Request: dummyReq("GET"), | ||
3157 | 1111 | - Header: Header{}, | ||
3158 | 1112 | + Header: http.Header{}, | ||
3159 | 1113 | Body: ioutil.NopCloser(strings.NewReader("abcdef")), | ||
3160 | 1114 | ContentLength: -1, | ||
3161 | 1115 | Close: true, | ||
3162 | 1116 | @@ -73,7 +74,7 @@ | ||
3163 | 1117 | ProtoMajor: 1, | ||
3164 | 1118 | ProtoMinor: 1, | ||
3165 | 1119 | Request: dummyReq11("GET"), | ||
3166 | 1120 | - Header: Header{}, | ||
3167 | 1121 | + Header: http.Header{}, | ||
3168 | 1122 | Body: ioutil.NopCloser(strings.NewReader("abcdef")), | ||
3169 | 1123 | ContentLength: -1, | ||
3170 | 1124 | Close: false, | ||
3171 | 1125 | @@ -91,7 +92,7 @@ | ||
3172 | 1126 | ProtoMajor: 1, | ||
3173 | 1127 | ProtoMinor: 1, | ||
3174 | 1128 | Request: dummyReq11("GET"), | ||
3175 | 1129 | - Header: Header{}, | ||
3176 | 1130 | + Header: http.Header{}, | ||
3177 | 1131 | Body: ioutil.NopCloser(strings.NewReader("abcdef")), | ||
3178 | 1132 | ContentLength: -1, | ||
3179 | 1133 | TransferEncoding: []string{"chunked"}, | ||
3180 | 1134 | @@ -108,7 +109,7 @@ | ||
3181 | 1135 | ProtoMajor: 1, | ||
3182 | 1136 | ProtoMinor: 1, | ||
3183 | 1137 | Request: dummyReq11("GET"), | ||
3184 | 1138 | - Header: Header{}, | ||
3185 | 1139 | + Header: http.Header{}, | ||
3186 | 1140 | Body: nil, | ||
3187 | 1141 | ContentLength: 0, | ||
3188 | 1142 | Close: false, | ||
3189 | 1143 | @@ -124,7 +125,7 @@ | ||
3190 | 1144 | ProtoMajor: 1, | ||
3191 | 1145 | ProtoMinor: 1, | ||
3192 | 1146 | Request: dummyReq11("GET"), | ||
3193 | 1147 | - Header: Header{}, | ||
3194 | 1148 | + Header: http.Header{}, | ||
3195 | 1149 | Body: ioutil.NopCloser(strings.NewReader("")), | ||
3196 | 1150 | ContentLength: 0, | ||
3197 | 1151 | Close: false, | ||
3198 | 1152 | @@ -140,7 +141,7 @@ | ||
3199 | 1153 | ProtoMajor: 1, | ||
3200 | 1154 | ProtoMinor: 1, | ||
3201 | 1155 | Request: dummyReq11("GET"), | ||
3202 | 1156 | - Header: Header{}, | ||
3203 | 1157 | + Header: http.Header{}, | ||
3204 | 1158 | Body: ioutil.NopCloser(strings.NewReader("foo")), | ||
3205 | 1159 | ContentLength: 0, | ||
3206 | 1160 | Close: false, | ||
3207 | 1161 | @@ -156,7 +157,7 @@ | ||
3208 | 1273 | ProtoMajor: 1, | 1162 | ProtoMajor: 1, |
3209 | 1274 | ProtoMinor: 1, | 1163 | ProtoMinor: 1, |
3210 | 1275 | Request: dummyReq("GET"), | 1164 | Request: dummyReq("GET"), |
3211 | @@ -1278,7 +1167,7 @@ | |||
3212 | 1278 | Body: ioutil.NopCloser(strings.NewReader("abcdef")), | 1167 | Body: ioutil.NopCloser(strings.NewReader("abcdef")), |
3213 | 1279 | ContentLength: 6, | 1168 | ContentLength: 6, |
3214 | 1280 | TransferEncoding: []string{"chunked"}, | 1169 | TransferEncoding: []string{"chunked"}, |
3216 | 1281 | @@ -77,7 +78,7 @@ | 1170 | @@ -177,7 +178,7 @@ |
3217 | 1282 | ProtoMajor: 1, | 1171 | ProtoMajor: 1, |
3218 | 1283 | ProtoMinor: 1, | 1172 | ProtoMinor: 1, |
3219 | 1284 | Request: dummyReq("GET"), | 1173 | Request: dummyReq("GET"), |
3220 | @@ -1287,11 +1176,20 @@ | |||
3221 | 1287 | "Foo": []string{" Bar\nBaz "}, | 1176 | "Foo": []string{" Bar\nBaz "}, |
3222 | 1288 | }, | 1177 | }, |
3223 | 1289 | Body: nil, | 1178 | Body: nil, |
3224 | 1179 | @@ -200,7 +201,7 @@ | ||
3225 | 1180 | ProtoMajor: 1, | ||
3226 | 1181 | ProtoMinor: 1, | ||
3227 | 1182 | Request: &Request{Method: "POST"}, | ||
3228 | 1183 | - Header: Header{}, | ||
3229 | 1184 | + Header: http.Header{}, | ||
3230 | 1185 | ContentLength: 0, | ||
3231 | 1186 | TransferEncoding: nil, | ||
3232 | 1187 | Body: nil, | ||
3233 | 1290 | 1188 | ||
3234 | 1291 | === modified file 'http13client/transport_test.go' | 1189 | === modified file 'http13client/transport_test.go' |
3238 | 1292 | --- http13client/transport_test.go 2014-03-19 21:38:56 +0000 | 1190 | --- http13client/transport_test.go 2014-06-20 11:00:47 +0000 |
3239 | 1293 | +++ http13client/transport_test.go 2014-03-19 22:27:37 +0000 | 1191 | +++ http13client/transport_test.go 2014-06-20 12:05:53 +0000 |
3240 | 1294 | @@ -17,8 +17,8 @@ | 1192 | @@ -18,8 +18,8 @@ |
3241 | 1295 | "io/ioutil" | 1193 | "io/ioutil" |
3242 | 1296 | "log" | 1194 | "log" |
3243 | 1297 | "net" | 1195 | "net" |
3244 | @@ -1301,7 +1199,7 @@ | |||
3245 | 1301 | "net/http/httptest" | 1199 | "net/http/httptest" |
3246 | 1302 | "net/url" | 1200 | "net/url" |
3247 | 1303 | "os" | 1201 | "os" |
3249 | 1304 | @@ -34,7 +34,7 @@ | 1202 | @@ -35,7 +35,7 @@ |
3250 | 1305 | // and then verify that the final 2 responses get errors back. | 1203 | // and then verify that the final 2 responses get errors back. |
3251 | 1306 | 1204 | ||
3252 | 1307 | // hostPortHandler writes back the client's "host:port". | 1205 | // hostPortHandler writes back the client's "host:port". |
3253 | @@ -1310,7 +1208,7 @@ | |||
3254 | 1310 | if r.FormValue("close") == "true" { | 1208 | if r.FormValue("close") == "true" { |
3255 | 1311 | w.Header().Set("Connection", "close") | 1209 | w.Header().Set("Connection", "close") |
3256 | 1312 | } | 1210 | } |
3258 | 1313 | @@ -280,7 +280,7 @@ | 1211 | @@ -289,7 +289,7 @@ |
3259 | 1314 | const msg = "foobar" | 1212 | const msg = "foobar" |
3260 | 1315 | 1213 | ||
3261 | 1316 | var addrSeen map[string]int | 1214 | var addrSeen map[string]int |
3262 | @@ -1319,7 +1217,7 @@ | |||
3263 | 1319 | addrSeen[r.RemoteAddr]++ | 1217 | addrSeen[r.RemoteAddr]++ |
3264 | 1320 | if r.URL.Path == "/chunked/" { | 1218 | if r.URL.Path == "/chunked/" { |
3265 | 1321 | w.WriteHeader(200) | 1219 | w.WriteHeader(200) |
3267 | 1322 | @@ -299,7 +299,7 @@ | 1220 | @@ -308,7 +308,7 @@ |
3268 | 1323 | wantLen := []int{len(msg), -1}[pi] | 1221 | wantLen := []int{len(msg), -1}[pi] |
3269 | 1324 | addrSeen = make(map[string]int) | 1222 | addrSeen = make(map[string]int) |
3270 | 1325 | for i := 0; i < 3; i++ { | 1223 | for i := 0; i < 3; i++ { |
3271 | @@ -1328,7 +1226,7 @@ | |||
3272 | 1328 | if err != nil { | 1226 | if err != nil { |
3273 | 1329 | t.Errorf("Get %s: %v", path, err) | 1227 | t.Errorf("Get %s: %v", path, err) |
3274 | 1330 | continue | 1228 | continue |
3276 | 1331 | @@ -329,7 +329,7 @@ | 1229 | @@ -338,7 +338,7 @@ |
3277 | 1332 | defer afterTest(t) | 1230 | defer afterTest(t) |
3278 | 1333 | resch := make(chan string) | 1231 | resch := make(chan string) |
3279 | 1334 | gotReq := make(chan bool) | 1232 | gotReq := make(chan bool) |
3280 | @@ -1337,7 +1235,7 @@ | |||
3281 | 1337 | gotReq <- true | 1235 | gotReq <- true |
3282 | 1338 | msg := <-resch | 1236 | msg := <-resch |
3283 | 1339 | _, err := w.Write([]byte(msg)) | 1237 | _, err := w.Write([]byte(msg)) |
3285 | 1340 | @@ -457,12 +457,12 @@ | 1238 | @@ -466,12 +466,12 @@ |
3286 | 1341 | if testing.Short() { | 1239 | if testing.Short() { |
3287 | 1342 | t.Skip("skipping test in short mode") | 1240 | t.Skip("skipping test in short mode") |
3288 | 1343 | } | 1241 | } |
3289 | @@ -1353,7 +1251,7 @@ | |||
3290 | 1353 | buf.Flush() | 1251 | buf.Flush() |
3291 | 1354 | conn.Close() | 1252 | conn.Close() |
3292 | 1355 | })) | 1253 | })) |
3294 | 1356 | @@ -510,7 +510,7 @@ | 1254 | @@ -519,7 +519,7 @@ |
3295 | 1357 | // with no bodies properly | 1255 | // with no bodies properly |
3296 | 1358 | func TestTransportHeadResponses(t *testing.T) { | 1256 | func TestTransportHeadResponses(t *testing.T) { |
3297 | 1359 | defer afterTest(t) | 1257 | defer afterTest(t) |
3298 | @@ -1362,7 +1260,7 @@ | |||
3299 | 1362 | if r.Method != "HEAD" { | 1260 | if r.Method != "HEAD" { |
3300 | 1363 | panic("expected HEAD; got " + r.Method) | 1261 | panic("expected HEAD; got " + r.Method) |
3301 | 1364 | } | 1262 | } |
3303 | 1365 | @@ -545,7 +545,7 @@ | 1263 | @@ -554,7 +554,7 @@ |
3304 | 1366 | // on responses to HEAD requests. | 1264 | // on responses to HEAD requests. |
3305 | 1367 | func TestTransportHeadChunkedResponse(t *testing.T) { | 1265 | func TestTransportHeadChunkedResponse(t *testing.T) { |
3306 | 1368 | defer afterTest(t) | 1266 | defer afterTest(t) |
3307 | @@ -1371,7 +1269,7 @@ | |||
3308 | 1371 | if r.Method != "HEAD" { | 1269 | if r.Method != "HEAD" { |
3309 | 1372 | panic("expected HEAD; got " + r.Method) | 1270 | panic("expected HEAD; got " + r.Method) |
3310 | 1373 | } | 1271 | } |
3312 | 1374 | @@ -588,7 +588,7 @@ | 1272 | @@ -597,7 +597,7 @@ |
3313 | 1375 | func TestRoundTripGzip(t *testing.T) { | 1273 | func TestRoundTripGzip(t *testing.T) { |
3314 | 1376 | defer afterTest(t) | 1274 | defer afterTest(t) |
3315 | 1377 | const responseBody = "test response body" | 1275 | const responseBody = "test response body" |
3316 | @@ -1380,7 +1278,7 @@ | |||
3317 | 1380 | accept := req.Header.Get("Accept-Encoding") | 1278 | accept := req.Header.Get("Accept-Encoding") |
3318 | 1381 | if expect := req.FormValue("expect_accept"); accept != expect { | 1279 | if expect := req.FormValue("expect_accept"); accept != expect { |
3319 | 1382 | t.Errorf("in handler, test %v: Accept-Encoding = %q, want %q", | 1280 | t.Errorf("in handler, test %v: Accept-Encoding = %q, want %q", |
3321 | 1383 | @@ -647,7 +647,7 @@ | 1281 | @@ -656,7 +656,7 @@ |
3322 | 1384 | defer afterTest(t) | 1282 | defer afterTest(t) |
3323 | 1385 | const testString = "The test string aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | 1283 | const testString = "The test string aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" |
3324 | 1386 | const nRandBytes = 1024 * 1024 | 1284 | const nRandBytes = 1024 * 1024 |
3325 | @@ -1389,7 +1287,7 @@ | |||
3326 | 1389 | if req.Method == "HEAD" { | 1287 | if req.Method == "HEAD" { |
3327 | 1390 | if g := req.Header.Get("Accept-Encoding"); g != "" { | 1288 | if g := req.Header.Get("Accept-Encoding"); g != "" { |
3328 | 1391 | t.Errorf("HEAD request sent with Accept-Encoding of %q; want none", g) | 1289 | t.Errorf("HEAD request sent with Accept-Encoding of %q; want none", g) |
3330 | 1392 | @@ -742,11 +742,11 @@ | 1290 | @@ -751,11 +751,11 @@ |
3331 | 1393 | func TestTransportProxy(t *testing.T) { | 1291 | func TestTransportProxy(t *testing.T) { |
3332 | 1394 | defer afterTest(t) | 1292 | defer afterTest(t) |
3333 | 1395 | ch := make(chan string, 1) | 1293 | ch := make(chan string, 1) |
3334 | @@ -1403,7 +1301,7 @@ | |||
3335 | 1403 | ch <- "proxy for " + r.URL.String() | 1301 | ch <- "proxy for " + r.URL.String() |
3336 | 1404 | })) | 1302 | })) |
3337 | 1405 | defer proxy.Close() | 1303 | defer proxy.Close() |
3339 | 1406 | @@ -770,7 +770,7 @@ | 1304 | @@ -779,7 +779,7 @@ |
3340 | 1407 | // Content-Encoding is removed. | 1305 | // Content-Encoding is removed. |
3341 | 1408 | func TestTransportGzipRecursive(t *testing.T) { | 1306 | func TestTransportGzipRecursive(t *testing.T) { |
3342 | 1409 | defer afterTest(t) | 1307 | defer afterTest(t) |
3343 | @@ -1412,7 +1310,16 @@ | |||
3344 | 1412 | w.Header().Set("Content-Encoding", "gzip") | 1310 | w.Header().Set("Content-Encoding", "gzip") |
3345 | 1413 | w.Write(rgz) | 1311 | w.Write(rgz) |
3346 | 1414 | })) | 1312 | })) |
3348 | 1415 | @@ -802,7 +802,7 @@ | 1313 | @@ -807,7 +807,7 @@ |
3349 | 1314 | // a short gzip body | ||
3350 | 1315 | func TestTransportGzipShort(t *testing.T) { | ||
3351 | 1316 | defer afterTest(t) | ||
3352 | 1317 | - ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) { | ||
3353 | 1318 | + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
3354 | 1319 | w.Header().Set("Content-Encoding", "gzip") | ||
3355 | 1320 | w.Write([]byte{0x1f, 0x8b}) | ||
3356 | 1321 | })) | ||
3357 | 1322 | @@ -838,7 +838,7 @@ | ||
3358 | 1416 | defer afterTest(t) | 1323 | defer afterTest(t) |
3359 | 1417 | gotReqCh := make(chan bool) | 1324 | gotReqCh := make(chan bool) |
3360 | 1418 | unblockCh := make(chan bool) | 1325 | unblockCh := make(chan bool) |
3361 | @@ -1421,7 +1328,7 @@ | |||
3362 | 1421 | gotReqCh <- true | 1328 | gotReqCh <- true |
3363 | 1422 | <-unblockCh | 1329 | <-unblockCh |
3364 | 1423 | w.Header().Set("Content-Length", "0") | 1330 | w.Header().Set("Content-Length", "0") |
3366 | 1424 | @@ -869,7 +869,7 @@ | 1331 | @@ -905,7 +905,7 @@ |
3367 | 1425 | t.Skip("skipping test; see http://golang.org/issue/7237") | 1332 | t.Skip("skipping test; see http://golang.org/issue/7237") |
3368 | 1426 | } | 1333 | } |
3369 | 1427 | defer afterTest(t) | 1334 | defer afterTest(t) |
3370 | @@ -1430,7 +1337,7 @@ | |||
3371 | 1430 | })) | 1337 | })) |
3372 | 1431 | defer ts.Close() | 1338 | defer ts.Close() |
3373 | 1432 | 1339 | ||
3375 | 1433 | @@ -912,7 +912,7 @@ | 1340 | @@ -948,7 +948,7 @@ |
3376 | 1434 | c := &Client{Transport: tr} | 1341 | c := &Client{Transport: tr} |
3377 | 1435 | 1342 | ||
3378 | 1436 | unblockCh := make(chan bool, 1) | 1343 | unblockCh := make(chan bool, 1) |
3379 | @@ -1439,7 +1346,7 @@ | |||
3380 | 1439 | <-unblockCh | 1346 | <-unblockCh |
3381 | 1440 | tr.CloseIdleConnections() | 1347 | tr.CloseIdleConnections() |
3382 | 1441 | })) | 1348 | })) |
3384 | 1442 | @@ -939,7 +939,7 @@ | 1349 | @@ -975,7 +975,7 @@ |
3385 | 1443 | func TestIssue3644(t *testing.T) { | 1350 | func TestIssue3644(t *testing.T) { |
3386 | 1444 | defer afterTest(t) | 1351 | defer afterTest(t) |
3387 | 1445 | const numFoos = 5000 | 1352 | const numFoos = 5000 |
3388 | @@ -1448,7 +1355,7 @@ | |||
3389 | 1448 | w.Header().Set("Connection", "close") | 1355 | w.Header().Set("Connection", "close") |
3390 | 1449 | for i := 0; i < numFoos; i++ { | 1356 | for i := 0; i < numFoos; i++ { |
3391 | 1450 | w.Write([]byte("foo ")) | 1357 | w.Write([]byte("foo ")) |
3393 | 1451 | @@ -967,8 +967,8 @@ | 1358 | @@ -1003,8 +1003,8 @@ |
3394 | 1452 | func TestIssue3595(t *testing.T) { | 1359 | func TestIssue3595(t *testing.T) { |
3395 | 1453 | defer afterTest(t) | 1360 | defer afterTest(t) |
3396 | 1454 | const deniedMsg = "sorry, denied." | 1361 | const deniedMsg = "sorry, denied." |
3397 | @@ -1459,7 +1366,7 @@ | |||
3398 | 1459 | })) | 1366 | })) |
3399 | 1460 | defer ts.Close() | 1367 | defer ts.Close() |
3400 | 1461 | tr := &Transport{} | 1368 | tr := &Transport{} |
3402 | 1462 | @@ -991,7 +991,7 @@ | 1369 | @@ -1027,7 +1027,7 @@ |
3403 | 1463 | // "client fails to handle requests with no body and chunked encoding" | 1370 | // "client fails to handle requests with no body and chunked encoding" |
3404 | 1464 | func TestChunkedNoContent(t *testing.T) { | 1371 | func TestChunkedNoContent(t *testing.T) { |
3405 | 1465 | defer afterTest(t) | 1372 | defer afterTest(t) |
3406 | @@ -1468,7 +1375,7 @@ | |||
3407 | 1468 | w.WriteHeader(StatusNoContent) | 1375 | w.WriteHeader(StatusNoContent) |
3408 | 1469 | })) | 1376 | })) |
3409 | 1470 | defer ts.Close() | 1377 | defer ts.Close() |
3411 | 1471 | @@ -1019,7 +1019,7 @@ | 1378 | @@ -1055,7 +1055,7 @@ |
3412 | 1472 | maxProcs, numReqs = 4, 50 | 1379 | maxProcs, numReqs = 4, 50 |
3413 | 1473 | } | 1380 | } |
3414 | 1474 | defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(maxProcs)) | 1381 | defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(maxProcs)) |
3415 | @@ -1477,7 +1384,7 @@ | |||
3416 | 1477 | fmt.Fprintf(w, "%v", r.FormValue("echo")) | 1384 | fmt.Fprintf(w, "%v", r.FormValue("echo")) |
3417 | 1478 | })) | 1385 | })) |
3418 | 1479 | defer ts.Close() | 1386 | defer ts.Close() |
3420 | 1480 | @@ -1080,8 +1080,8 @@ | 1387 | @@ -1116,8 +1116,8 @@ |
3421 | 1481 | } | 1388 | } |
3422 | 1482 | defer afterTest(t) | 1389 | defer afterTest(t) |
3423 | 1483 | const debug = false | 1390 | const debug = false |
3424 | @@ -1488,7 +1395,7 @@ | |||
3425 | 1488 | io.Copy(w, neverEnding('a')) | 1395 | io.Copy(w, neverEnding('a')) |
3426 | 1489 | }) | 1396 | }) |
3427 | 1490 | ts := httptest.NewServer(mux) | 1397 | ts := httptest.NewServer(mux) |
3429 | 1491 | @@ -1144,11 +1144,11 @@ | 1398 | @@ -1180,11 +1180,11 @@ |
3430 | 1492 | } | 1399 | } |
3431 | 1493 | defer afterTest(t) | 1400 | defer afterTest(t) |
3432 | 1494 | const debug = false | 1401 | const debug = false |
3433 | @@ -1503,20 +1410,22 @@ | |||
3434 | 1503 | defer r.Body.Close() | 1410 | defer r.Body.Close() |
3435 | 1504 | io.Copy(ioutil.Discard, r.Body) | 1411 | io.Copy(ioutil.Discard, r.Body) |
3436 | 1505 | }) | 1412 | }) |
3439 | 1506 | @@ -1214,9 +1214,9 @@ | 1413 | @@ -1251,11 +1251,11 @@ |
3438 | 1507 | if testing.Short() { | ||
3440 | 1508 | t.Skip("skipping timeout test in -short mode") | 1414 | t.Skip("skipping timeout test in -short mode") |
3441 | 1509 | } | 1415 | } |
3442 | 1416 | inHandler := make(chan bool, 1) | ||
3443 | 1510 | - mux := NewServeMux() | 1417 | - mux := NewServeMux() |
3445 | 1511 | - mux.HandleFunc("/fast", func(w ResponseWriter, r *Request) {}) | 1418 | - mux.HandleFunc("/fast", func(w ResponseWriter, r *Request) { |
3446 | 1419 | + mux := http.NewServeMux() | ||
3447 | 1420 | + mux.HandleFunc("/fast", func(w http.ResponseWriter, r *http.Request) { | ||
3448 | 1421 | inHandler <- true | ||
3449 | 1422 | }) | ||
3450 | 1512 | - mux.HandleFunc("/slow", func(w ResponseWriter, r *Request) { | 1423 | - mux.HandleFunc("/slow", func(w ResponseWriter, r *Request) { |
3451 | 1513 | + mux := http.NewServeMux() | ||
3452 | 1514 | + mux.HandleFunc("/fast", func(w http.ResponseWriter, r *http.Request) {}) | ||
3453 | 1515 | + mux.HandleFunc("/slow", func(w http.ResponseWriter, r *http.Request) { | 1424 | + mux.HandleFunc("/slow", func(w http.ResponseWriter, r *http.Request) { |
3454 | 1425 | inHandler <- true | ||
3455 | 1516 | time.Sleep(2 * time.Second) | 1426 | time.Sleep(2 * time.Second) |
3456 | 1517 | }) | 1427 | }) |
3459 | 1518 | ts := httptest.NewServer(mux) | 1428 | @@ -1322,9 +1322,9 @@ |
3458 | 1519 | @@ -1276,9 +1276,9 @@ | ||
3460 | 1520 | t.Skip("skipping test in -short mode") | 1429 | t.Skip("skipping test in -short mode") |
3461 | 1521 | } | 1430 | } |
3462 | 1522 | unblockc := make(chan bool) | 1431 | unblockc := make(chan bool) |
3463 | @@ -1528,7 +1437,7 @@ | |||
3464 | 1528 | <-unblockc | 1437 | <-unblockc |
3465 | 1529 | })) | 1438 | })) |
3466 | 1530 | defer ts.Close() | 1439 | defer ts.Close() |
3468 | 1531 | @@ -1386,14 +1386,14 @@ | 1440 | @@ -1431,14 +1431,14 @@ |
3469 | 1532 | defer afterTest(t) | 1441 | defer afterTest(t) |
3470 | 1533 | writeErr := make(chan error, 1) | 1442 | writeErr := make(chan error, 1) |
3471 | 1534 | msg := []byte("young\n") | 1443 | msg := []byte("young\n") |
3472 | @@ -1545,7 +1454,7 @@ | |||
3473 | 1545 | } | 1454 | } |
3474 | 1546 | })) | 1455 | })) |
3475 | 1547 | defer ts.Close() | 1456 | defer ts.Close() |
3477 | 1548 | @@ -1449,7 +1449,7 @@ | 1457 | @@ -1494,7 +1494,7 @@ |
3478 | 1549 | res := &Response{ | 1458 | res := &Response{ |
3479 | 1550 | Status: "200 OK", | 1459 | Status: "200 OK", |
3480 | 1551 | StatusCode: 200, | 1460 | StatusCode: 200, |
3481 | @@ -1554,7 +1463,7 @@ | |||
3482 | 1554 | Body: ioutil.NopCloser(strings.NewReader("You wanted " + req.URL.String())), | 1463 | Body: ioutil.NopCloser(strings.NewReader("You wanted " + req.URL.String())), |
3483 | 1555 | } | 1464 | } |
3484 | 1556 | return res, nil | 1465 | return res, nil |
3486 | 1557 | @@ -1478,7 +1478,7 @@ | 1466 | @@ -1523,7 +1523,7 @@ |
3487 | 1558 | defer afterTest(t) | 1467 | defer afterTest(t) |
3488 | 1559 | tr := &Transport{} | 1468 | tr := &Transport{} |
3489 | 1560 | _, err := tr.RoundTrip(&Request{ | 1469 | _, err := tr.RoundTrip(&Request{ |
3490 | @@ -1563,7 +1472,7 @@ | |||
3491 | 1563 | URL: &url.URL{ | 1472 | URL: &url.URL{ |
3492 | 1564 | Scheme: "http", | 1473 | Scheme: "http", |
3493 | 1565 | }, | 1474 | }, |
3495 | 1566 | @@ -1492,14 +1492,14 @@ | 1475 | @@ -1537,14 +1537,14 @@ |
3496 | 1567 | func TestTransportSocketLateBinding(t *testing.T) { | 1476 | func TestTransportSocketLateBinding(t *testing.T) { |
3497 | 1568 | defer afterTest(t) | 1477 | defer afterTest(t) |
3498 | 1569 | 1478 | ||
3499 | @@ -1582,7 +1491,7 @@ | |||
3500 | 1582 | w.Header().Set("bar-ipport", r.RemoteAddr) | 1491 | w.Header().Set("bar-ipport", r.RemoteAddr) |
3501 | 1583 | }) | 1492 | }) |
3502 | 1584 | ts := httptest.NewServer(mux) | 1493 | ts := httptest.NewServer(mux) |
3504 | 1585 | @@ -1720,7 +1720,7 @@ | 1494 | @@ -1767,7 +1767,7 @@ |
3505 | 1586 | var mu sync.Mutex | 1495 | var mu sync.Mutex |
3506 | 1587 | var n int | 1496 | var n int |
3507 | 1588 | 1497 | ||
3508 | @@ -1591,7 +1500,7 @@ | |||
3509 | 1591 | mu.Lock() | 1500 | mu.Lock() |
3510 | 1592 | n++ | 1501 | n++ |
3511 | 1593 | mu.Unlock() | 1502 | mu.Unlock() |
3513 | 1594 | @@ -1756,7 +1756,7 @@ | 1503 | @@ -1803,7 +1803,7 @@ |
3514 | 1595 | // then closes it. | 1504 | // then closes it. |
3515 | 1596 | func TestTransportClosesRequestBody(t *testing.T) { | 1505 | func TestTransportClosesRequestBody(t *testing.T) { |
3516 | 1597 | defer afterTest(t) | 1506 | defer afterTest(t) |
3517 | @@ -1600,4 +1509,49 @@ | |||
3518 | 1600 | io.Copy(ioutil.Discard, r.Body) | 1509 | io.Copy(ioutil.Discard, r.Body) |
3519 | 1601 | })) | 1510 | })) |
3520 | 1602 | defer ts.Close() | 1511 | defer ts.Close() |
3521 | 1512 | @@ -1890,9 +1890,9 @@ | ||
3522 | 1513 | t.Skip("skipping flaky test on Windows; golang.org/issue/7634") | ||
3523 | 1514 | } | ||
3524 | 1515 | closedc := make(chan bool, 1) | ||
3525 | 1516 | - ts := httptest.NewTLSServer(HandlerFunc(func(w ResponseWriter, r *Request) { | ||
3526 | 1517 | + ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
3527 | 1518 | if strings.Contains(r.URL.Path, "/keep-alive-then-die") { | ||
3528 | 1519 | - conn, _, _ := w.(Hijacker).Hijack() | ||
3529 | 1520 | + conn, _, _ := w.(http.Hijacker).Hijack() | ||
3530 | 1521 | conn.Write([]byte("HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nfoo")) | ||
3531 | 1522 | conn.Close() | ||
3532 | 1523 | closedc <- true | ||
3533 | 1524 | @@ -1994,12 +1994,12 @@ | ||
3534 | 1525 | } | ||
3535 | 1526 | defer closeConn() | ||
3536 | 1527 | |||
3537 | 1528 | - ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) { | ||
3538 | 1529 | + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
3539 | 1530 | if r.Method == "GET" { | ||
3540 | 1531 | io.WriteString(w, "bar") | ||
3541 | 1532 | return | ||
3542 | 1533 | } | ||
3543 | 1534 | - conn, _, _ := w.(Hijacker).Hijack() | ||
3544 | 1535 | + conn, _, _ := w.(http.Hijacker).Hijack() | ||
3545 | 1536 | sconn.Lock() | ||
3546 | 1537 | sconn.c = conn | ||
3547 | 1538 | sconn.Unlock() | ||
3548 | 1539 | @@ -2056,7 +2056,7 @@ | ||
3549 | 1540 | } | ||
3550 | 1541 | defer afterTest(t) | ||
3551 | 1542 | readBody := make(chan error, 1) | ||
3552 | 1543 | - ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) { | ||
3553 | 1544 | + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
3554 | 1545 | _, err := ioutil.ReadAll(r.Body) | ||
3555 | 1546 | readBody <- err | ||
3556 | 1547 | })) | ||
3557 | 1548 | @@ -2098,7 +2098,7 @@ | ||
3558 | 1549 | } | ||
3559 | 1550 | } | ||
3560 | 1551 | |||
3561 | 1552 | -func wantBody(res *http.Response, err error, want string) error { | ||
3562 | 1553 | +func wantBody(res *Response, err error, want string) error { | ||
3563 | 1554 | if err != nil { | ||
3564 | 1555 | return err | ||
3565 | 1556 | } | ||
3566 | 1603 | 1557 | ||
3567 | 1604 | 1558 | ||
3568 | === modified file 'http13client/_using.txt' | |||
3569 | --- http13client/_using.txt 2014-03-20 12:20:01 +0000 | |||
3570 | +++ http13client/_using.txt 2014-06-20 13:02:58 +0000 | |||
3571 | @@ -1,5 +1,5 @@ | |||
3575 | 1 | parent: 19512:32c32aef2a41 tip | 1 | parent: 20169:9895f9e36435 go1.3 release |
3576 | 2 | test: enable bug385_32 test on amd64p32. | 2 | go1.3 |
3577 | 3 | branch: default | 3 | branch: release-branch.go1.3 |
3578 | 4 | commit: (clean) | 4 | commit: (clean) |
3579 | 5 | update: (current) | 5 | update: (current) |
3580 | 6 | 6 | ||
3581 | === modified file 'http13client/client.go' | |||
3582 | --- http13client/client.go 2014-03-20 09:26:28 +0000 | |||
3583 | +++ http13client/client.go 2014-06-20 13:02:58 +0000 | |||
3584 | @@ -92,8 +92,9 @@ | |||
3585 | 92 | // authentication, or cookies. | 92 | // authentication, or cookies. |
3586 | 93 | // | 93 | // |
3587 | 94 | // RoundTrip should not modify the request, except for | 94 | // RoundTrip should not modify the request, except for |
3590 | 95 | // consuming and closing the Body. The request's URL and | 95 | // consuming and closing the Body, including on errors. The |
3591 | 96 | // Header fields are guaranteed to be initialized. | 96 | // request's URL and Header fields are guaranteed to be |
3592 | 97 | // initialized. | ||
3593 | 97 | RoundTrip(*Request) (*Response, error) | 98 | RoundTrip(*Request) (*Response, error) |
3594 | 98 | } | 99 | } |
3595 | 99 | 100 | ||
3596 | @@ -141,6 +142,9 @@ | |||
3597 | 141 | // (typically Transport) may not be able to re-use a persistent TCP | 142 | // (typically Transport) may not be able to re-use a persistent TCP |
3598 | 142 | // connection to the server for a subsequent "keep-alive" request. | 143 | // connection to the server for a subsequent "keep-alive" request. |
3599 | 143 | // | 144 | // |
3600 | 145 | // The request Body, if non-nil, will be closed by the underlying | ||
3601 | 146 | // Transport, even on errors. | ||
3602 | 147 | // | ||
3603 | 144 | // Generally Get, Post, or PostForm will be used instead of Do. | 148 | // Generally Get, Post, or PostForm will be used instead of Do. |
3604 | 145 | func (c *Client) Do(req *Request) (resp *Response, err error) { | 149 | func (c *Client) Do(req *Request) (resp *Response, err error) { |
3605 | 146 | if req.Method == "GET" || req.Method == "HEAD" { | 150 | if req.Method == "GET" || req.Method == "HEAD" { |
3606 | @@ -163,14 +167,17 @@ | |||
3607 | 163 | // Caller should close resp.Body when done reading from it. | 167 | // Caller should close resp.Body when done reading from it. |
3608 | 164 | func send(req *Request, t RoundTripper) (resp *Response, err error) { | 168 | func send(req *Request, t RoundTripper) (resp *Response, err error) { |
3609 | 165 | if t == nil { | 169 | if t == nil { |
3610 | 170 | req.closeBody() | ||
3611 | 166 | return nil, errors.New("http: no Client.Transport or DefaultTransport") | 171 | return nil, errors.New("http: no Client.Transport or DefaultTransport") |
3612 | 167 | } | 172 | } |
3613 | 168 | 173 | ||
3614 | 169 | if req.URL == nil { | 174 | if req.URL == nil { |
3615 | 175 | req.closeBody() | ||
3616 | 170 | return nil, errors.New("http: nil Request.URL") | 176 | return nil, errors.New("http: nil Request.URL") |
3617 | 171 | } | 177 | } |
3618 | 172 | 178 | ||
3619 | 173 | if req.RequestURI != "" { | 179 | if req.RequestURI != "" { |
3620 | 180 | req.closeBody() | ||
3621 | 174 | return nil, errors.New("http: Request.RequestURI can't be set in client requests.") | 181 | return nil, errors.New("http: Request.RequestURI can't be set in client requests.") |
3622 | 175 | } | 182 | } |
3623 | 176 | 183 | ||
3624 | @@ -278,6 +285,7 @@ | |||
3625 | 278 | var via []*Request | 285 | var via []*Request |
3626 | 279 | 286 | ||
3627 | 280 | if ireq.URL == nil { | 287 | if ireq.URL == nil { |
3628 | 288 | ireq.closeBody() | ||
3629 | 281 | return nil, errors.New("http: nil Request.URL") | 289 | return nil, errors.New("http: nil Request.URL") |
3630 | 282 | } | 290 | } |
3631 | 283 | 291 | ||
3632 | @@ -400,7 +408,7 @@ | |||
3633 | 400 | // Caller should close resp.Body when done reading from it. | 408 | // Caller should close resp.Body when done reading from it. |
3634 | 401 | // | 409 | // |
3635 | 402 | // If the provided body is also an io.Closer, it is closed after the | 410 | // If the provided body is also an io.Closer, it is closed after the |
3637 | 403 | // body is successfully written to the server. | 411 | // request. |
3638 | 404 | func (c *Client) Post(url string, bodyType string, body io.Reader) (resp *Response, err error) { | 412 | func (c *Client) Post(url string, bodyType string, body io.Reader) (resp *Response, err error) { |
3639 | 405 | req, err := NewRequest("POST", url, body) | 413 | req, err := NewRequest("POST", url, body) |
3640 | 406 | if err != nil { | 414 | if err != nil { |
3641 | 407 | 415 | ||
3642 | === modified file 'http13client/client_test.go' | |||
3643 | --- http13client/client_test.go 2014-03-20 09:26:28 +0000 | |||
3644 | +++ http13client/client_test.go 2014-06-20 13:02:58 +0000 | |||
3645 | @@ -20,6 +20,8 @@ | |||
3646 | 20 | "net/http" | 20 | "net/http" |
3647 | 21 | "net/http/httptest" | 21 | "net/http/httptest" |
3648 | 22 | "net/url" | 22 | "net/url" |
3649 | 23 | "reflect" | ||
3650 | 24 | "sort" | ||
3651 | 23 | "strconv" | 25 | "strconv" |
3652 | 24 | "strings" | 26 | "strings" |
3653 | 25 | "sync" | 27 | "sync" |
3654 | @@ -877,3 +879,93 @@ | |||
3655 | 877 | t.Fatal("server saw different client ports before & after the redirect") | 879 | t.Fatal("server saw different client ports before & after the redirect") |
3656 | 878 | } | 880 | } |
3657 | 879 | } | 881 | } |
3658 | 882 | |||
3659 | 883 | // eofReaderFunc is an io.Reader that runs itself, and then returns io.EOF. | ||
3660 | 884 | type eofReaderFunc func() | ||
3661 | 885 | |||
3662 | 886 | func (f eofReaderFunc) Read(p []byte) (n int, err error) { | ||
3663 | 887 | f() | ||
3664 | 888 | return 0, io.EOF | ||
3665 | 889 | } | ||
3666 | 890 | |||
3667 | 891 | func TestClientTrailers(t *testing.T) { | ||
3668 | 892 | defer afterTest(t) | ||
3669 | 893 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
3670 | 894 | w.Header().Set("Connection", "close") | ||
3671 | 895 | w.Header().Set("Trailer", "Server-Trailer-A, Server-Trailer-B") | ||
3672 | 896 | w.Header().Add("Trailer", "Server-Trailer-C") | ||
3673 | 897 | |||
3674 | 898 | var decl []string | ||
3675 | 899 | for k := range r.Trailer { | ||
3676 | 900 | decl = append(decl, k) | ||
3677 | 901 | } | ||
3678 | 902 | sort.Strings(decl) | ||
3679 | 903 | |||
3680 | 904 | slurp, err := ioutil.ReadAll(r.Body) | ||
3681 | 905 | if err != nil { | ||
3682 | 906 | t.Errorf("Server reading request body: %v", err) | ||
3683 | 907 | } | ||
3684 | 908 | if string(slurp) != "foo" { | ||
3685 | 909 | t.Errorf("Server read request body %q; want foo", slurp) | ||
3686 | 910 | } | ||
3687 | 911 | if r.Trailer == nil { | ||
3688 | 912 | io.WriteString(w, "nil Trailer") | ||
3689 | 913 | } else { | ||
3690 | 914 | fmt.Fprintf(w, "decl: %v, vals: %s, %s", | ||
3691 | 915 | decl, | ||
3692 | 916 | r.Trailer.Get("Client-Trailer-A"), | ||
3693 | 917 | r.Trailer.Get("Client-Trailer-B")) | ||
3694 | 918 | } | ||
3695 | 919 | |||
3696 | 920 | // TODO: golang.org/issue/7759: there's no way yet for | ||
3697 | 921 | // the server to set trailers without hijacking, so do | ||
3698 | 922 | // that for now, just to test the client. Later, in | ||
3699 | 923 | // Go 1.4, it should be implicit that any mutations | ||
3700 | 924 | // to w.Header() after the initial write are the | ||
3701 | 925 | // trailers to be sent, if and only if they were | ||
3702 | 926 | // previously declared with w.Header().Set("Trailer", | ||
3703 | 927 | // ..keys..) | ||
3704 | 928 | w.(http.Flusher).Flush() | ||
3705 | 929 | conn, buf, _ := w.(http.Hijacker).Hijack() | ||
3706 | 930 | t := http.Header{} | ||
3707 | 931 | t.Set("Server-Trailer-A", "valuea") | ||
3708 | 932 | t.Set("Server-Trailer-C", "valuec") // skipping B | ||
3709 | 933 | buf.WriteString("0\r\n") // eof | ||
3710 | 934 | t.Write(buf) | ||
3711 | 935 | buf.WriteString("\r\n") // end of trailers | ||
3712 | 936 | buf.Flush() | ||
3713 | 937 | conn.Close() | ||
3714 | 938 | })) | ||
3715 | 939 | defer ts.Close() | ||
3716 | 940 | |||
3717 | 941 | var req *Request | ||
3718 | 942 | req, _ = NewRequest("POST", ts.URL, io.MultiReader( | ||
3719 | 943 | eofReaderFunc(func() { | ||
3720 | 944 | req.Trailer["Client-Trailer-A"] = []string{"valuea"} | ||
3721 | 945 | }), | ||
3722 | 946 | strings.NewReader("foo"), | ||
3723 | 947 | eofReaderFunc(func() { | ||
3724 | 948 | req.Trailer["Client-Trailer-B"] = []string{"valueb"} | ||
3725 | 949 | }), | ||
3726 | 950 | )) | ||
3727 | 951 | req.Trailer = http.Header{ | ||
3728 | 952 | "Client-Trailer-A": nil, // to be set later | ||
3729 | 953 | "Client-Trailer-B": nil, // to be set later | ||
3730 | 954 | } | ||
3731 | 955 | req.ContentLength = -1 | ||
3732 | 956 | res, err := DefaultClient.Do(req) | ||
3733 | 957 | if err != nil { | ||
3734 | 958 | t.Fatal(err) | ||
3735 | 959 | } | ||
3736 | 960 | if err := wantBody(res, err, "decl: [Client-Trailer-A Client-Trailer-B], vals: valuea, valueb"); err != nil { | ||
3737 | 961 | t.Error(err) | ||
3738 | 962 | } | ||
3739 | 963 | want := http.Header{ | ||
3740 | 964 | "Server-Trailer-A": []string{"valuea"}, | ||
3741 | 965 | "Server-Trailer-B": nil, | ||
3742 | 966 | "Server-Trailer-C": []string{"valuec"}, | ||
3743 | 967 | } | ||
3744 | 968 | if !reflect.DeepEqual(res.Trailer, want) { | ||
3745 | 969 | t.Errorf("Response trailers = %#v; want %#v", res.Trailer, want) | ||
3746 | 970 | } | ||
3747 | 971 | } | ||
3748 | 880 | 972 | ||
3749 | === modified file 'http13client/cookie.go' | |||
3750 | --- http13client/cookie.go 2014-03-19 23:13:58 +0000 | |||
3751 | +++ http13client/cookie.go 2014-06-20 13:02:58 +0000 | |||
3752 | @@ -55,11 +55,7 @@ | |||
3753 | 55 | attr, val = attr[:j], attr[j+1:] | 55 | attr, val = attr[:j], attr[j+1:] |
3754 | 56 | } | 56 | } |
3755 | 57 | lowerAttr := strings.ToLower(attr) | 57 | lowerAttr := strings.ToLower(attr) |
3761 | 58 | parseCookieValueFn := parseCookieValue | 58 | val, success = parseCookieValue(val) |
3757 | 59 | if lowerAttr == "expires" { | ||
3758 | 60 | parseCookieValueFn = parseCookieExpiresValue | ||
3759 | 61 | } | ||
3760 | 62 | val, success = parseCookieValueFn(val) | ||
3762 | 63 | if !success { | 59 | if !success { |
3763 | 64 | c.Unparsed = append(c.Unparsed, parts[i]) | 60 | c.Unparsed = append(c.Unparsed, parts[i]) |
3764 | 65 | continue | 61 | continue |
3765 | @@ -230,12 +226,23 @@ | |||
3766 | 230 | // ; US-ASCII characters excluding CTLs, | 226 | // ; US-ASCII characters excluding CTLs, |
3767 | 231 | // ; whitespace DQUOTE, comma, semicolon, | 227 | // ; whitespace DQUOTE, comma, semicolon, |
3768 | 232 | // ; and backslash | 228 | // ; and backslash |
3769 | 229 | // We loosen this as spaces and commas are common in cookie values | ||
3770 | 230 | // but we produce a quoted cookie-value in when value starts or ends | ||
3771 | 231 | // with a comma or space. | ||
3772 | 232 | // See http://golang.org/issue/7243 for the discussion. | ||
3773 | 233 | func sanitizeCookieValue(v string) string { | 233 | func sanitizeCookieValue(v string) string { |
3775 | 234 | return sanitizeOrWarn("Cookie.Value", validCookieValueByte, v) | 234 | v = sanitizeOrWarn("Cookie.Value", validCookieValueByte, v) |
3776 | 235 | if len(v) == 0 { | ||
3777 | 236 | return v | ||
3778 | 237 | } | ||
3779 | 238 | if v[0] == ' ' || v[0] == ',' || v[len(v)-1] == ' ' || v[len(v)-1] == ',' { | ||
3780 | 239 | return `"` + v + `"` | ||
3781 | 240 | } | ||
3782 | 241 | return v | ||
3783 | 235 | } | 242 | } |
3784 | 236 | 243 | ||
3785 | 237 | func validCookieValueByte(b byte) bool { | 244 | func validCookieValueByte(b byte) bool { |
3787 | 238 | return 0x20 < b && b < 0x7f && b != '"' && b != ',' && b != ';' && b != '\\' | 245 | return 0x20 <= b && b < 0x7f && b != '"' && b != ';' && b != '\\' |
3788 | 239 | } | 246 | } |
3789 | 240 | 247 | ||
3790 | 241 | // path-av = "Path=" path-value | 248 | // path-av = "Path=" path-value |
3791 | @@ -270,38 +277,13 @@ | |||
3792 | 270 | return string(buf) | 277 | return string(buf) |
3793 | 271 | } | 278 | } |
3794 | 272 | 279 | ||
3795 | 273 | func unquoteCookieValue(v string) string { | ||
3796 | 274 | if len(v) > 1 && v[0] == '"' && v[len(v)-1] == '"' { | ||
3797 | 275 | return v[1 : len(v)-1] | ||
3798 | 276 | } | ||
3799 | 277 | return v | ||
3800 | 278 | } | ||
3801 | 279 | |||
3802 | 280 | func isCookieByte(c byte) bool { | ||
3803 | 281 | switch { | ||
3804 | 282 | case c == 0x21, 0x23 <= c && c <= 0x2b, 0x2d <= c && c <= 0x3a, | ||
3805 | 283 | 0x3c <= c && c <= 0x5b, 0x5d <= c && c <= 0x7e: | ||
3806 | 284 | return true | ||
3807 | 285 | } | ||
3808 | 286 | return false | ||
3809 | 287 | } | ||
3810 | 288 | |||
3811 | 289 | func isCookieExpiresByte(c byte) (ok bool) { | ||
3812 | 290 | return isCookieByte(c) || c == ',' || c == ' ' | ||
3813 | 291 | } | ||
3814 | 292 | |||
3815 | 293 | func parseCookieValue(raw string) (string, bool) { | 280 | func parseCookieValue(raw string) (string, bool) { |
3825 | 294 | return parseCookieValueUsing(raw, isCookieByte) | 281 | // Strip the quotes, if present. |
3826 | 295 | } | 282 | if len(raw) > 1 && raw[0] == '"' && raw[len(raw)-1] == '"' { |
3827 | 296 | 283 | raw = raw[1 : len(raw)-1] | |
3828 | 297 | func parseCookieExpiresValue(raw string) (string, bool) { | 284 | } |
3820 | 298 | return parseCookieValueUsing(raw, isCookieExpiresByte) | ||
3821 | 299 | } | ||
3822 | 300 | |||
3823 | 301 | func parseCookieValueUsing(raw string, validByte func(byte) bool) (string, bool) { | ||
3824 | 302 | raw = unquoteCookieValue(raw) | ||
3829 | 303 | for i := 0; i < len(raw); i++ { | 285 | for i := 0; i < len(raw); i++ { |
3831 | 304 | if !validByte(raw[i]) { | 286 | if !validCookieValueByte(raw[i]) { |
3832 | 305 | return "", false | 287 | return "", false |
3833 | 306 | } | 288 | } |
3834 | 307 | } | 289 | } |
3835 | 308 | 290 | ||
3836 | === removed file 'http13client/cookie_test.go' | |||
3837 | --- http13client/cookie_test.go 2014-03-19 23:13:58 +0000 | |||
3838 | +++ http13client/cookie_test.go 1970-01-01 00:00:00 +0000 | |||
3839 | @@ -1,304 +0,0 @@ | |||
3840 | 1 | // Copyright 2010 The Go Authors. All rights reserved. | ||
3841 | 2 | // Use of this source code is governed by a BSD-style | ||
3842 | 3 | // license that can be found in the LICENSE file. | ||
3843 | 4 | |||
3844 | 5 | package http | ||
3845 | 6 | |||
3846 | 7 | import ( | ||
3847 | 8 | "bytes" | ||
3848 | 9 | "encoding/json" | ||
3849 | 10 | "fmt" | ||
3850 | 11 | "log" | ||
3851 | 12 | "net/http" | ||
3852 | 13 | "os" | ||
3853 | 14 | "reflect" | ||
3854 | 15 | "strings" | ||
3855 | 16 | "testing" | ||
3856 | 17 | "time" | ||
3857 | 18 | ) | ||
3858 | 19 | |||
3859 | 20 | var writeSetCookiesTests = []struct { | ||
3860 | 21 | Cookie *http.Cookie | ||
3861 | 22 | Raw string | ||
3862 | 23 | }{ | ||
3863 | 24 | { | ||
3864 | 25 | &http.Cookie{Name: "cookie-1", Value: "v$1"}, | ||
3865 | 26 | "cookie-1=v$1", | ||
3866 | 27 | }, | ||
3867 | 28 | { | ||
3868 | 29 | &http.Cookie{Name: "cookie-2", Value: "two", MaxAge: 3600}, | ||
3869 | 30 | "cookie-2=two; Max-Age=3600", | ||
3870 | 31 | }, | ||
3871 | 32 | { | ||
3872 | 33 | &http.Cookie{Name: "cookie-3", Value: "three", Domain: ".example.com"}, | ||
3873 | 34 | "cookie-3=three; Domain=example.com", | ||
3874 | 35 | }, | ||
3875 | 36 | { | ||
3876 | 37 | &http.Cookie{Name: "cookie-4", Value: "four", Path: "/restricted/"}, | ||
3877 | 38 | "cookie-4=four; Path=/restricted/", | ||
3878 | 39 | }, | ||
3879 | 40 | { | ||
3880 | 41 | &http.Cookie{Name: "cookie-5", Value: "five", Domain: "wrong;bad.abc"}, | ||
3881 | 42 | "cookie-5=five", | ||
3882 | 43 | }, | ||
3883 | 44 | { | ||
3884 | 45 | &http.Cookie{Name: "cookie-6", Value: "six", Domain: "bad-.abc"}, | ||
3885 | 46 | "cookie-6=six", | ||
3886 | 47 | }, | ||
3887 | 48 | { | ||
3888 | 49 | &http.Cookie{Name: "cookie-7", Value: "seven", Domain: "127.0.0.1"}, | ||
3889 | 50 | "cookie-7=seven; Domain=127.0.0.1", | ||
3890 | 51 | }, | ||
3891 | 52 | { | ||
3892 | 53 | &http.Cookie{Name: "cookie-8", Value: "eight", Domain: "::1"}, | ||
3893 | 54 | "cookie-8=eight", | ||
3894 | 55 | }, | ||
3895 | 56 | } | ||
3896 | 57 | |||
3897 | 58 | func TestWriteSetCookies(t *testing.T) { | ||
3898 | 59 | defer log.SetOutput(os.Stderr) | ||
3899 | 60 | var logbuf bytes.Buffer | ||
3900 | 61 | log.SetOutput(&logbuf) | ||
3901 | 62 | |||
3902 | 63 | for i, tt := range writeSetCookiesTests { | ||
3903 | 64 | if g, e := tt.Cookie.String(), tt.Raw; g != e { | ||
3904 | 65 | t.Errorf("Test %d, expecting:\n%s\nGot:\n%s\n", i, e, g) | ||
3905 | 66 | continue | ||
3906 | 67 | } | ||
3907 | 68 | } | ||
3908 | 69 | |||
3909 | 70 | if got, sub := logbuf.String(), "dropping domain attribute"; !strings.Contains(got, sub) { | ||
3910 | 71 | t.Errorf("Expected substring %q in log output. Got:\n%s", sub, got) | ||
3911 | 72 | } | ||
3912 | 73 | } | ||
3913 | 74 | |||
3914 | 75 | type headerOnlyResponseWriter http.Header | ||
3915 | 76 | |||
3916 | 77 | func (ho headerOnlyResponseWriter) Header() http.Header { | ||
3917 | 78 | return http.Header(ho) | ||
3918 | 79 | } | ||
3919 | 80 | |||
3920 | 81 | func (ho headerOnlyResponseWriter) Write([]byte) (int, error) { | ||
3921 | 82 | panic("NOIMPL") | ||
3922 | 83 | } | ||
3923 | 84 | |||
3924 | 85 | func (ho headerOnlyResponseWriter) WriteHeader(int) { | ||
3925 | 86 | panic("NOIMPL") | ||
3926 | 87 | } | ||
3927 | 88 | |||
3928 | 89 | func TestSetCookie(t *testing.T) { | ||
3929 | 90 | m := make(http.Header) | ||
3930 | 91 | http.SetCookie(headerOnlyResponseWriter(m), &http.Cookie{Name: "cookie-1", Value: "one", Path: "/restricted/"}) | ||
3931 | 92 | http.SetCookie(headerOnlyResponseWriter(m), &http.Cookie{Name: "cookie-2", Value: "two", MaxAge: 3600}) | ||
3932 | 93 | if l := len(m["Set-Cookie"]); l != 2 { | ||
3933 | 94 | t.Fatalf("expected %d cookies, got %d", 2, l) | ||
3934 | 95 | } | ||
3935 | 96 | if g, e := m["Set-Cookie"][0], "cookie-1=one; Path=/restricted/"; g != e { | ||
3936 | 97 | t.Errorf("cookie #1: want %q, got %q", e, g) | ||
3937 | 98 | } | ||
3938 | 99 | if g, e := m["Set-Cookie"][1], "cookie-2=two; Max-Age=3600"; g != e { | ||
3939 | 100 | t.Errorf("cookie #2: want %q, got %q", e, g) | ||
3940 | 101 | } | ||
3941 | 102 | } | ||
3942 | 103 | |||
3943 | 104 | var addCookieTests = []struct { | ||
3944 | 105 | Cookies []*http.Cookie | ||
3945 | 106 | Raw string | ||
3946 | 107 | }{ | ||
3947 | 108 | { | ||
3948 | 109 | []*http.Cookie{}, | ||
3949 | 110 | "", | ||
3950 | 111 | }, | ||
3951 | 112 | { | ||
3952 | 113 | []*http.Cookie{{Name: "cookie-1", Value: "v$1"}}, | ||
3953 | 114 | "cookie-1=v$1", | ||
3954 | 115 | }, | ||
3955 | 116 | { | ||
3956 | 117 | []*http.Cookie{ | ||
3957 | 118 | {Name: "cookie-1", Value: "v$1"}, | ||
3958 | 119 | {Name: "cookie-2", Value: "v$2"}, | ||
3959 | 120 | {Name: "cookie-3", Value: "v$3"}, | ||
3960 | 121 | }, | ||
3961 | 122 | "cookie-1=v$1; cookie-2=v$2; cookie-3=v$3", | ||
3962 | 123 | }, | ||
3963 | 124 | } | ||
3964 | 125 | |||
3965 | 126 | func TestAddCookie(t *testing.T) { | ||
3966 | 127 | for i, tt := range addCookieTests { | ||
3967 | 128 | req, _ := NewRequest("GET", "http://example.com/", nil) | ||
3968 | 129 | for _, c := range tt.Cookies { | ||
3969 | 130 | req.AddCookie(c) | ||
3970 | 131 | } | ||
3971 | 132 | if g := req.Header.Get("Cookie"); g != tt.Raw { | ||
3972 | 133 | t.Errorf("Test %d:\nwant: %s\n got: %s\n", i, tt.Raw, g) | ||
3973 | 134 | continue | ||
3974 | 135 | } | ||
3975 | 136 | } | ||
3976 | 137 | } | ||
3977 | 138 | |||
3978 | 139 | var readSetCookiesTests = []struct { | ||
3979 | 140 | Header http.Header | ||
3980 | 141 | Cookies []*http.Cookie | ||
3981 | 142 | }{ | ||
3982 | 143 | { | ||
3983 | 144 | http.Header{"Set-Cookie": {"Cookie-1=v$1"}}, | ||
3984 | 145 | []*http.Cookie{{Name: "Cookie-1", Value: "v$1", Raw: "Cookie-1=v$1"}}, | ||
3985 | 146 | }, | ||
3986 | 147 | { | ||
3987 | 148 | http.Header{"Set-Cookie": {"NID=99=YsDT5i3E-CXax-; expires=Wed, 23-Nov-2011 01:05:03 GMT; path=/; domain=.google.ch; HttpOnly"}}, | ||
3988 | 149 | []*http.Cookie{{ | ||
3989 | 150 | Name: "NID", | ||
3990 | 151 | Value: "99=YsDT5i3E-CXax-", | ||
3991 | 152 | Path: "/", | ||
3992 | 153 | Domain: ".google.ch", | ||
3993 | 154 | HttpOnly: true, | ||
3994 | 155 | Expires: time.Date(2011, 11, 23, 1, 5, 3, 0, time.UTC), | ||
3995 | 156 | RawExpires: "Wed, 23-Nov-2011 01:05:03 GMT", | ||
3996 | 157 | Raw: "NID=99=YsDT5i3E-CXax-; expires=Wed, 23-Nov-2011 01:05:03 GMT; path=/; domain=.google.ch; HttpOnly", | ||
3997 | 158 | }}, | ||
3998 | 159 | }, | ||
3999 | 160 | { | ||
4000 | 161 | http.Header{"Set-Cookie": {".ASPXAUTH=7E3AA; expires=Wed, 07-Mar-2012 14:25:06 GMT; path=/; HttpOnly"}}, | ||
4001 | 162 | []*http.Cookie{{ | ||
4002 | 163 | Name: ".ASPXAUTH", | ||
4003 | 164 | Value: "7E3AA", | ||
4004 | 165 | Path: "/", | ||
4005 | 166 | Expires: time.Date(2012, 3, 7, 14, 25, 6, 0, time.UTC), | ||
4006 | 167 | RawExpires: "Wed, 07-Mar-2012 14:25:06 GMT", | ||
4007 | 168 | HttpOnly: true, | ||
4008 | 169 | Raw: ".ASPXAUTH=7E3AA; expires=Wed, 07-Mar-2012 14:25:06 GMT; path=/; HttpOnly", | ||
4009 | 170 | }}, | ||
4010 | 171 | }, | ||
4011 | 172 | { | ||
4012 | 173 | http.Header{"Set-Cookie": {"ASP.NET_SessionId=foo; path=/; HttpOnly"}}, | ||
4013 | 174 | []*http.Cookie{{ | ||
4014 | 175 | Name: "ASP.NET_SessionId", | ||
4015 | 176 | Value: "foo", | ||
4016 | 177 | Path: "/", | ||
4017 | 178 | HttpOnly: true, | ||
4018 | 179 | Raw: "ASP.NET_SessionId=foo; path=/; HttpOnly", | ||
4019 | 180 | }}, | ||
4020 | 181 | }, | ||
4021 | 182 | |||
4022 | 183 | // TODO(bradfitz): users have reported seeing this in the | ||
4023 | 184 | // wild, but do browsers handle it? RFC 6265 just says "don't | ||
4024 | 185 | // do that" (section 3) and then never mentions header folding | ||
4025 | 186 | // again. | ||
4026 | 187 | // Header{"Set-Cookie": {"ASP.NET_SessionId=foo; path=/; HttpOnly, .ASPXAUTH=7E3AA; expires=Wed, 07-Mar-2012 14:25:06 GMT; path=/; HttpOnly"}}, | ||
4027 | 188 | } | ||
4028 | 189 | |||
4029 | 190 | func toJSON(v interface{}) string { | ||
4030 | 191 | b, err := json.Marshal(v) | ||
4031 | 192 | if err != nil { | ||
4032 | 193 | return fmt.Sprintf("%#v", v) | ||
4033 | 194 | } | ||
4034 | 195 | return string(b) | ||
4035 | 196 | } | ||
4036 | 197 | |||
4037 | 198 | func TestReadSetCookies(t *testing.T) { | ||
4038 | 199 | for i, tt := range readSetCookiesTests { | ||
4039 | 200 | for n := 0; n < 2; n++ { // to verify readSetCookies doesn't mutate its input | ||
4040 | 201 | c := readSetCookies(tt.Header) | ||
4041 | 202 | if !reflect.DeepEqual(c, tt.Cookies) { | ||
4042 | 203 | t.Errorf("#%d readSetCookies: have\n%s\nwant\n%s\n", i, toJSON(c), toJSON(tt.Cookies)) | ||
4043 | 204 | continue | ||
4044 | 205 | } | ||
4045 | 206 | } | ||
4046 | 207 | } | ||
4047 | 208 | } | ||
4048 | 209 | |||
4049 | 210 | var readCookiesTests = []struct { | ||
4050 | 211 | Header http.Header | ||
4051 | 212 | Filter string | ||
4052 | 213 | Cookies []*http.Cookie | ||
4053 | 214 | }{ | ||
4054 | 215 | { | ||
4055 | 216 | http.Header{"Cookie": {"Cookie-1=v$1", "c2=v2"}}, | ||
4056 | 217 | "", | ||
4057 | 218 | []*http.Cookie{ | ||
4058 | 219 | {Name: "Cookie-1", Value: "v$1"}, | ||
4059 | 220 | {Name: "c2", Value: "v2"}, | ||
4060 | 221 | }, | ||
4061 | 222 | }, | ||
4062 | 223 | { | ||
4063 | 224 | http.Header{"Cookie": {"Cookie-1=v$1", "c2=v2"}}, | ||
4064 | 225 | "c2", | ||
4065 | 226 | []*http.Cookie{ | ||
4066 | 227 | {Name: "c2", Value: "v2"}, | ||
4067 | 228 | }, | ||
4068 | 229 | }, | ||
4069 | 230 | { | ||
4070 | 231 | http.Header{"Cookie": {"Cookie-1=v$1; c2=v2"}}, | ||
4071 | 232 | "", | ||
4072 | 233 | []*http.Cookie{ | ||
4073 | 234 | {Name: "Cookie-1", Value: "v$1"}, | ||
4074 | 235 | {Name: "c2", Value: "v2"}, | ||
4075 | 236 | }, | ||
4076 | 237 | }, | ||
4077 | 238 | { | ||
4078 | 239 | http.Header{"Cookie": {"Cookie-1=v$1; c2=v2"}}, | ||
4079 | 240 | "c2", | ||
4080 | 241 | []*http.Cookie{ | ||
4081 | 242 | {Name: "c2", Value: "v2"}, | ||
4082 | 243 | }, | ||
4083 | 244 | }, | ||
4084 | 245 | } | ||
4085 | 246 | |||
4086 | 247 | func TestReadCookies(t *testing.T) { | ||
4087 | 248 | for i, tt := range readCookiesTests { | ||
4088 | 249 | for n := 0; n < 2; n++ { // to verify readCookies doesn't mutate its input | ||
4089 | 250 | c := readCookies(tt.Header, tt.Filter) | ||
4090 | 251 | if !reflect.DeepEqual(c, tt.Cookies) { | ||
4091 | 252 | t.Errorf("#%d readCookies:\nhave: %s\nwant: %s\n", i, toJSON(c), toJSON(tt.Cookies)) | ||
4092 | 253 | continue | ||
4093 | 254 | } | ||
4094 | 255 | } | ||
4095 | 256 | } | ||
4096 | 257 | } | ||
4097 | 258 | |||
4098 | 259 | func TestCookieSanitizeValue(t *testing.T) { | ||
4099 | 260 | defer log.SetOutput(os.Stderr) | ||
4100 | 261 | var logbuf bytes.Buffer | ||
4101 | 262 | log.SetOutput(&logbuf) | ||
4102 | 263 | |||
4103 | 264 | tests := []struct { | ||
4104 | 265 | in, want string | ||
4105 | 266 | }{ | ||
4106 | 267 | {"foo", "foo"}, | ||
4107 | 268 | {"foo bar", "foobar"}, | ||
4108 | 269 | {"\x00\x7e\x7f\x80", "\x7e"}, | ||
4109 | 270 | {`"withquotes"`, "withquotes"}, | ||
4110 | 271 | } | ||
4111 | 272 | for _, tt := range tests { | ||
4112 | 273 | if got := sanitizeCookieValue(tt.in); got != tt.want { | ||
4113 | 274 | t.Errorf("sanitizeCookieValue(%q) = %q; want %q", tt.in, got, tt.want) | ||
4114 | 275 | } | ||
4115 | 276 | } | ||
4116 | 277 | |||
4117 | 278 | if got, sub := logbuf.String(), "dropping invalid bytes"; !strings.Contains(got, sub) { | ||
4118 | 279 | t.Errorf("Expected substring %q in log output. Got:\n%s", sub, got) | ||
4119 | 280 | } | ||
4120 | 281 | } | ||
4121 | 282 | |||
4122 | 283 | func TestCookieSanitizePath(t *testing.T) { | ||
4123 | 284 | defer log.SetOutput(os.Stderr) | ||
4124 | 285 | var logbuf bytes.Buffer | ||
4125 | 286 | log.SetOutput(&logbuf) | ||
4126 | 287 | |||
4127 | 288 | tests := []struct { | ||
4128 | 289 | in, want string | ||
4129 | 290 | }{ | ||
4130 | 291 | {"/path", "/path"}, | ||
4131 | 292 | {"/path with space/", "/path with space/"}, | ||
4132 | 293 | {"/just;no;semicolon\x00orstuff/", "/justnosemicolonorstuff/"}, | ||
4133 | 294 | } | ||
4134 | 295 | for _, tt := range tests { | ||
4135 | 296 | if got := sanitizeCookiePath(tt.in); got != tt.want { | ||
4136 | 297 | t.Errorf("sanitizeCookiePath(%q) = %q; want %q", tt.in, got, tt.want) | ||
4137 | 298 | } | ||
4138 | 299 | } | ||
4139 | 300 | |||
4140 | 301 | if got, sub := logbuf.String(), "dropping invalid bytes"; !strings.Contains(got, sub) { | ||
4141 | 302 | t.Errorf("Expected substring %q in log output. Got:\n%s", sub, got) | ||
4142 | 303 | } | ||
4143 | 304 | } | ||
4144 | 305 | 0 | ||
4145 | === modified file 'http13client/request.go' | |||
4146 | --- http13client/request.go 2014-03-19 23:13:58 +0000 | |||
4147 | +++ http13client/request.go 2014-06-20 13:02:58 +0000 | |||
4148 | @@ -69,18 +69,31 @@ | |||
4149 | 69 | 69 | ||
4150 | 70 | // A Request represents an HTTP request received by a server | 70 | // A Request represents an HTTP request received by a server |
4151 | 71 | // or to be sent by a client. | 71 | // or to be sent by a client. |
4152 | 72 | // | ||
4153 | 73 | // The field semantics differ slightly between client and server | ||
4154 | 74 | // usage. In addition to the notes on the fields below, see the | ||
4155 | 75 | // documentation for Request.Write and RoundTripper. | ||
4156 | 72 | type Request struct { | 76 | type Request struct { |
4158 | 73 | Method string // GET, POST, PUT, etc. | 77 | // Method specifies the HTTP method (GET, POST, PUT, etc.). |
4159 | 78 | // For client requests an empty string means GET. | ||
4160 | 79 | Method string | ||
4161 | 74 | 80 | ||
4167 | 75 | // URL is created from the URI supplied on the Request-Line | 81 | // URL specifies either the URI being requested (for server |
4168 | 76 | // as stored in RequestURI. | 82 | // requests) or the URL to access (for client requests). |
4169 | 77 | // | 83 | // |
4170 | 78 | // For most requests, fields other than Path and RawQuery | 84 | // For server requests the URL is parsed from the URI |
4171 | 79 | // will be empty. (See RFC 2616, Section 5.1.2) | 85 | // supplied on the Request-Line as stored in RequestURI. For |
4172 | 86 | // most requests, fields other than Path and RawQuery will be | ||
4173 | 87 | // empty. (See RFC 2616, Section 5.1.2) | ||
4174 | 88 | // | ||
4175 | 89 | // For client requests, the URL's Host specifies the server to | ||
4176 | 90 | // connect to, while the Request's Host field optionally | ||
4177 | 91 | // specifies the Host header value to send in the HTTP | ||
4178 | 92 | // request. | ||
4179 | 80 | URL *url.URL | 93 | URL *url.URL |
4180 | 81 | 94 | ||
4181 | 82 | // The protocol version for incoming requests. | 95 | // The protocol version for incoming requests. |
4183 | 83 | // Outgoing requests always use HTTP/1.1. | 96 | // Client requests always use HTTP/1.1. |
4184 | 84 | Proto string // "HTTP/1.0" | 97 | Proto string // "HTTP/1.0" |
4185 | 85 | ProtoMajor int // 1 | 98 | ProtoMajor int // 1 |
4186 | 86 | ProtoMinor int // 0 | 99 | ProtoMinor int // 0 |
4187 | @@ -104,15 +117,20 @@ | |||
4188 | 104 | // The request parser implements this by canonicalizing the | 117 | // The request parser implements this by canonicalizing the |
4189 | 105 | // name, making the first character and any characters | 118 | // name, making the first character and any characters |
4190 | 106 | // following a hyphen uppercase and the rest lowercase. | 119 | // following a hyphen uppercase and the rest lowercase. |
4191 | 120 | // | ||
4192 | 121 | // For client requests certain headers are automatically | ||
4193 | 122 | // added and may override values in Header. | ||
4194 | 123 | // | ||
4195 | 124 | // See the documentation for the Request.Write method. | ||
4196 | 107 | Header http.Header | 125 | Header http.Header |
4197 | 108 | 126 | ||
4198 | 109 | // Body is the request's body. | 127 | // Body is the request's body. |
4199 | 110 | // | 128 | // |
4201 | 111 | // For client requests, a nil body means the request has no | 129 | // For client requests a nil body means the request has no |
4202 | 112 | // body, such as a GET request. The HTTP Client's Transport | 130 | // body, such as a GET request. The HTTP Client's Transport |
4203 | 113 | // is responsible for calling the Close method. | 131 | // is responsible for calling the Close method. |
4204 | 114 | // | 132 | // |
4206 | 115 | // For server requests, the Request Body is always non-nil | 133 | // For server requests the Request Body is always non-nil |
4207 | 116 | // but will return EOF immediately when no body is present. | 134 | // but will return EOF immediately when no body is present. |
4208 | 117 | // The Server will close the request body. The ServeHTTP | 135 | // The Server will close the request body. The ServeHTTP |
4209 | 118 | // Handler does not need to. | 136 | // Handler does not need to. |
4210 | @@ -122,7 +140,7 @@ | |||
4211 | 122 | // The value -1 indicates that the length is unknown. | 140 | // The value -1 indicates that the length is unknown. |
4212 | 123 | // Values >= 0 indicate that the given number of bytes may | 141 | // Values >= 0 indicate that the given number of bytes may |
4213 | 124 | // be read from Body. | 142 | // be read from Body. |
4215 | 125 | // For outgoing requests, a value of 0 means unknown if Body is not nil. | 143 | // For client requests, a value of 0 means unknown if Body is not nil. |
4216 | 126 | ContentLength int64 | 144 | ContentLength int64 |
4217 | 127 | 145 | ||
4218 | 128 | // TransferEncoding lists the transfer encodings from outermost to | 146 | // TransferEncoding lists the transfer encodings from outermost to |
4219 | @@ -133,13 +151,18 @@ | |||
4220 | 133 | TransferEncoding []string | 151 | TransferEncoding []string |
4221 | 134 | 152 | ||
4222 | 135 | // Close indicates whether to close the connection after | 153 | // Close indicates whether to close the connection after |
4224 | 136 | // replying to this request. | 154 | // replying to this request (for servers) or after sending |
4225 | 155 | // the request (for clients). | ||
4226 | 137 | Close bool | 156 | Close bool |
4227 | 138 | 157 | ||
4231 | 139 | // The host on which the URL is sought. | 158 | // For server requests Host specifies the host on which the |
4232 | 140 | // Per RFC 2616, this is either the value of the Host: header | 159 | // URL is sought. Per RFC 2616, this is either the value of |
4233 | 141 | // or the host name given in the URL itself. | 160 | // the "Host" header or the host name given in the URL itself. |
4234 | 142 | // It may be of the form "host:port". | 161 | // It may be of the form "host:port". |
4235 | 162 | // | ||
4236 | 163 | // For client requests Host optionally overrides the Host | ||
4237 | 164 | // header to send. If empty, the Request.Write method uses | ||
4238 | 165 | // the value of URL.Host. | ||
4239 | 143 | Host string | 166 | Host string |
4240 | 144 | 167 | ||
4241 | 145 | // Form contains the parsed form data, including both the URL | 168 | // Form contains the parsed form data, including both the URL |
4242 | @@ -159,12 +182,24 @@ | |||
4243 | 159 | // The HTTP client ignores MultipartForm and uses Body instead. | 182 | // The HTTP client ignores MultipartForm and uses Body instead. |
4244 | 160 | MultipartForm *multipart.Form | 183 | MultipartForm *multipart.Form |
4245 | 161 | 184 | ||
4252 | 162 | // Trailer maps trailer keys to values. Like for Header, if the | 185 | // Trailer specifies additional headers that are sent after the request |
4253 | 163 | // response has multiple trailer lines with the same key, they will be | 186 | // body. |
4254 | 164 | // concatenated, delimited by commas. | 187 | // |
4255 | 165 | // For server requests, Trailer is only populated after Body has been | 188 | // For server requests the Trailer map initially contains only the |
4256 | 166 | // closed or fully consumed. | 189 | // trailer keys, with nil values. (The client declares which trailers it |
4257 | 167 | // Trailer support is only partially complete. | 190 | // will later send.) While the handler is reading from Body, it must |
4258 | 191 | // not reference Trailer. After reading from Body returns EOF, Trailer | ||
4259 | 192 | // can be read again and will contain non-nil values, if they were sent | ||
4260 | 193 | // by the client. | ||
4261 | 194 | // | ||
4262 | 195 | // For client requests Trailer must be initialized to a map containing | ||
4263 | 196 | // the trailer keys to later send. The values may be nil or their final | ||
4264 | 197 | // values. The ContentLength must be 0 or -1, to send a chunked request. | ||
4265 | 198 | // After the HTTP request is sent the map values can be updated while | ||
4266 | 199 | // the request body is read. Once the body returns EOF, the caller must | ||
4267 | 200 | // not mutate Trailer. | ||
4268 | 201 | // | ||
4269 | 202 | // Few HTTP clients, servers, or proxies support HTTP trailers. | ||
4270 | 168 | Trailer http.Header | 203 | Trailer http.Header |
4271 | 169 | 204 | ||
4272 | 170 | // RemoteAddr allows HTTP servers and other software to record | 205 | // RemoteAddr allows HTTP servers and other software to record |
4273 | @@ -382,7 +417,6 @@ | |||
4274 | 382 | return err | 417 | return err |
4275 | 383 | } | 418 | } |
4276 | 384 | 419 | ||
4277 | 385 | // TODO: split long values? (If so, should share code with Conn.Write) | ||
4278 | 386 | err = req.Header.WriteSubset(w, reqWriteExcludeHeader) | 420 | err = req.Header.WriteSubset(w, reqWriteExcludeHeader) |
4279 | 387 | if err != nil { | 421 | if err != nil { |
4280 | 388 | return err | 422 | return err |
4281 | @@ -589,32 +623,6 @@ | |||
4282 | 589 | 623 | ||
4283 | 590 | fixPragmaCacheControl(req.Header) | 624 | fixPragmaCacheControl(req.Header) |
4284 | 591 | 625 | ||
4285 | 592 | // TODO: Parse specific header values: | ||
4286 | 593 | // Accept | ||
4287 | 594 | // Accept-Encoding | ||
4288 | 595 | // Accept-Language | ||
4289 | 596 | // Authorization | ||
4290 | 597 | // Cache-Control | ||
4291 | 598 | // Connection | ||
4292 | 599 | // Date | ||
4293 | 600 | // Expect | ||
4294 | 601 | // From | ||
4295 | 602 | // If-Match | ||
4296 | 603 | // If-Modified-Since | ||
4297 | 604 | // If-None-Match | ||
4298 | 605 | // If-Range | ||
4299 | 606 | // If-Unmodified-Since | ||
4300 | 607 | // Max-Forwards | ||
4301 | 608 | // Proxy-Authorization | ||
4302 | 609 | // Referer [sic] | ||
4303 | 610 | // TE (transfer-codings) | ||
4304 | 611 | // Trailer | ||
4305 | 612 | // Transfer-Encoding | ||
4306 | 613 | // Upgrade | ||
4307 | 614 | // User-Agent | ||
4308 | 615 | // Via | ||
4309 | 616 | // Warning | ||
4310 | 617 | |||
4311 | 618 | err = readTransfer(req, b) | 626 | err = readTransfer(req, b) |
4312 | 619 | if err != nil { | 627 | if err != nil { |
4313 | 620 | return nil, err | 628 | return nil, err |
4314 | @@ -783,9 +791,7 @@ | |||
4315 | 783 | } | 791 | } |
4316 | 784 | 792 | ||
4317 | 785 | mr, err := r.multipartReader() | 793 | mr, err := r.multipartReader() |
4321 | 786 | if err == ErrNotMultipart { | 794 | if err != nil { |
4319 | 787 | return nil | ||
4320 | 788 | } else if err != nil { | ||
4322 | 789 | return err | 795 | return err |
4323 | 790 | } | 796 | } |
4324 | 791 | 797 | ||
4325 | @@ -863,3 +869,9 @@ | |||
4326 | 863 | func (r *Request) wantsClose() bool { | 869 | func (r *Request) wantsClose() bool { |
4327 | 864 | return hasToken(r.Header.Get("Connection"), "close") | 870 | return hasToken(r.Header.Get("Connection"), "close") |
4328 | 865 | } | 871 | } |
4329 | 872 | |||
4330 | 873 | func (r *Request) closeBody() { | ||
4331 | 874 | if r.Body != nil { | ||
4332 | 875 | r.Body.Close() | ||
4333 | 876 | } | ||
4334 | 877 | } | ||
4335 | 866 | 878 | ||
4336 | === modified file 'http13client/request_test.go' | |||
4337 | --- http13client/request_test.go 2014-03-20 09:26:28 +0000 | |||
4338 | +++ http13client/request_test.go 2014-06-20 13:02:58 +0000 | |||
4339 | @@ -155,7 +155,25 @@ | |||
4340 | 155 | req.Header = http.Header{"Content-Type": {"text/plain"}} | 155 | req.Header = http.Header{"Content-Type": {"text/plain"}} |
4341 | 156 | multipart, err = req.MultipartReader() | 156 | multipart, err = req.MultipartReader() |
4342 | 157 | if multipart != nil { | 157 | if multipart != nil { |
4344 | 158 | t.Errorf("unexpected multipart for text/plain") | 158 | t.Error("unexpected multipart for text/plain") |
4345 | 159 | } | ||
4346 | 160 | } | ||
4347 | 161 | |||
4348 | 162 | func TestParseMultipartForm(t *testing.T) { | ||
4349 | 163 | req := &Request{ | ||
4350 | 164 | Method: "POST", | ||
4351 | 165 | Header: http.Header{"Content-Type": {`multipart/form-data; boundary="foo123"`}}, | ||
4352 | 166 | Body: ioutil.NopCloser(new(bytes.Buffer)), | ||
4353 | 167 | } | ||
4354 | 168 | err := req.ParseMultipartForm(25) | ||
4355 | 169 | if err == nil { | ||
4356 | 170 | t.Error("expected multipart EOF, got nil") | ||
4357 | 171 | } | ||
4358 | 172 | |||
4359 | 173 | req.Header = http.Header{"Content-Type": {"text/plain"}} | ||
4360 | 174 | err = req.ParseMultipartForm(25) | ||
4361 | 175 | if err != ErrNotMultipart { | ||
4362 | 176 | t.Error("expected ErrNotMultipart for text/plain") | ||
4363 | 159 | } | 177 | } |
4364 | 160 | } | 178 | } |
4365 | 161 | 179 | ||
4366 | @@ -221,16 +239,38 @@ | |||
4367 | 221 | validateTestMultipartContents(t, req, true) | 239 | validateTestMultipartContents(t, req, true) |
4368 | 222 | } | 240 | } |
4369 | 223 | 241 | ||
4377 | 224 | func TestEmptyMultipartRequest(t *testing.T) { | 242 | func TestMissingFileMultipartRequest(t *testing.T) { |
4378 | 225 | // Test that FormValue and FormFile automatically invoke | 243 | // Test that FormFile returns an error if |
4379 | 226 | // ParseMultipartForm and return the right values. | 244 | // the named file is missing. |
4380 | 227 | req, err := NewRequest("GET", "/", nil) | 245 | req := newTestMultipartRequest(t) |
4374 | 228 | if err != nil { | ||
4375 | 229 | t.Errorf("NewRequest err = %q", err) | ||
4376 | 230 | } | ||
4381 | 231 | testMissingFile(t, req) | 246 | testMissingFile(t, req) |
4382 | 232 | } | 247 | } |
4383 | 233 | 248 | ||
4384 | 249 | // Test that FormValue invokes ParseMultipartForm. | ||
4385 | 250 | func TestFormValueCallsParseMultipartForm(t *testing.T) { | ||
4386 | 251 | req, _ := NewRequest("POST", "http://www.google.com/", strings.NewReader("z=post")) | ||
4387 | 252 | req.Header.Set("Content-Type", "application/x-www-form-urlencoded; param=value") | ||
4388 | 253 | if req.Form != nil { | ||
4389 | 254 | t.Fatal("Unexpected request Form, want nil") | ||
4390 | 255 | } | ||
4391 | 256 | req.FormValue("z") | ||
4392 | 257 | if req.Form == nil { | ||
4393 | 258 | t.Fatal("ParseMultipartForm not called by FormValue") | ||
4394 | 259 | } | ||
4395 | 260 | } | ||
4396 | 261 | |||
4397 | 262 | // Test that FormFile invokes ParseMultipartForm. | ||
4398 | 263 | func TestFormFileCallsParseMultipartForm(t *testing.T) { | ||
4399 | 264 | req := newTestMultipartRequest(t) | ||
4400 | 265 | if req.Form != nil { | ||
4401 | 266 | t.Fatal("Unexpected request Form, want nil") | ||
4402 | 267 | } | ||
4403 | 268 | req.FormFile("") | ||
4404 | 269 | if req.Form == nil { | ||
4405 | 270 | t.Fatal("ParseMultipartForm not called by FormFile") | ||
4406 | 271 | } | ||
4407 | 272 | } | ||
4408 | 273 | |||
4409 | 234 | // Test that ParseMultipartForm errors if called | 274 | // Test that ParseMultipartForm errors if called |
4410 | 235 | // after MultipartReader on the same request. | 275 | // after MultipartReader on the same request. |
4411 | 236 | func TestParseMultipartFormOrder(t *testing.T) { | 276 | func TestParseMultipartFormOrder(t *testing.T) { |
4412 | 237 | 277 | ||
4413 | === modified file 'http13client/response.go' | |||
4414 | --- http13client/response.go 2014-03-19 23:43:25 +0000 | |||
4415 | +++ http13client/response.go 2014-06-20 13:02:58 +0000 | |||
4416 | @@ -8,6 +8,7 @@ | |||
4417 | 8 | 8 | ||
4418 | 9 | import ( | 9 | import ( |
4419 | 10 | "bufio" | 10 | "bufio" |
4420 | 11 | "bytes" | ||
4421 | 11 | "crypto/tls" | 12 | "crypto/tls" |
4422 | 12 | "errors" | 13 | "errors" |
4423 | 13 | "io" | 14 | "io" |
4424 | @@ -47,7 +48,8 @@ | |||
4425 | 47 | // | 48 | // |
4426 | 48 | // The http Client and Transport guarantee that Body is always | 49 | // The http Client and Transport guarantee that Body is always |
4427 | 49 | // non-nil, even on responses without a body or responses with | 50 | // non-nil, even on responses without a body or responses with |
4429 | 50 | // a zero-lengthed body. | 51 | // a zero-length body. It is the caller's responsibility to |
4430 | 52 | // close Body. | ||
4431 | 51 | // | 53 | // |
4432 | 52 | // The Body is automatically dechunked if the server replied | 54 | // The Body is automatically dechunked if the server replied |
4433 | 53 | // with a "chunked" Transfer-Encoding. | 55 | // with a "chunked" Transfer-Encoding. |
4434 | @@ -200,7 +202,6 @@ | |||
4435 | 200 | // | 202 | // |
4436 | 201 | // Body is closed after it is sent. | 203 | // Body is closed after it is sent. |
4437 | 202 | func (r *Response) Write(w io.Writer) error { | 204 | func (r *Response) Write(w io.Writer) error { |
4438 | 203 | |||
4439 | 204 | // Status line | 205 | // Status line |
4440 | 205 | text := r.Status | 206 | text := r.Status |
4441 | 206 | if text == "" { | 207 | if text == "" { |
4442 | @@ -212,10 +213,45 @@ | |||
4443 | 212 | protoMajor, protoMinor := strconv.Itoa(r.ProtoMajor), strconv.Itoa(r.ProtoMinor) | 213 | protoMajor, protoMinor := strconv.Itoa(r.ProtoMajor), strconv.Itoa(r.ProtoMinor) |
4444 | 213 | statusCode := strconv.Itoa(r.StatusCode) + " " | 214 | statusCode := strconv.Itoa(r.StatusCode) + " " |
4445 | 214 | text = strings.TrimPrefix(text, statusCode) | 215 | text = strings.TrimPrefix(text, statusCode) |
4447 | 215 | io.WriteString(w, "HTTP/"+protoMajor+"."+protoMinor+" "+statusCode+text+"\r\n") | 216 | if _, err := io.WriteString(w, "HTTP/"+protoMajor+"."+protoMinor+" "+statusCode+text+"\r\n"); err != nil { |
4448 | 217 | return err | ||
4449 | 218 | } | ||
4450 | 219 | |||
4451 | 220 | // Clone it, so we can modify r1 as needed. | ||
4452 | 221 | r1 := new(Response) | ||
4453 | 222 | *r1 = *r | ||
4454 | 223 | if r1.ContentLength == 0 && r1.Body != nil { | ||
4455 | 224 | // Is it actually 0 length? Or just unknown? | ||
4456 | 225 | var buf [1]byte | ||
4457 | 226 | n, err := r1.Body.Read(buf[:]) | ||
4458 | 227 | if err != nil && err != io.EOF { | ||
4459 | 228 | return err | ||
4460 | 229 | } | ||
4461 | 230 | if n == 0 { | ||
4462 | 231 | // Reset it to a known zero reader, in case underlying one | ||
4463 | 232 | // is unhappy being read repeatedly. | ||
4464 | 233 | r1.Body = eofReader | ||
4465 | 234 | } else { | ||
4466 | 235 | r1.ContentLength = -1 | ||
4467 | 236 | r1.Body = struct { | ||
4468 | 237 | io.Reader | ||
4469 | 238 | io.Closer | ||
4470 | 239 | }{ | ||
4471 | 240 | io.MultiReader(bytes.NewReader(buf[:1]), r.Body), | ||
4472 | 241 | r.Body, | ||
4473 | 242 | } | ||
4474 | 243 | } | ||
4475 | 244 | } | ||
4476 | 245 | // If we're sending a non-chunked HTTP/1.1 response without a | ||
4477 | 246 | // content-length, the only way to do that is the old HTTP/1.0 | ||
4478 | 247 | // way, by noting the EOF with a connection close, so we need | ||
4479 | 248 | // to set Close. | ||
4480 | 249 | if r1.ContentLength == -1 && !r1.Close && r1.ProtoAtLeast(1, 1) && !chunked(r1.TransferEncoding) { | ||
4481 | 250 | r1.Close = true | ||
4482 | 251 | } | ||
4483 | 216 | 252 | ||
4484 | 217 | // Process Body,ContentLength,Close,Trailer | 253 | // Process Body,ContentLength,Close,Trailer |
4486 | 218 | tw, err := newTransferWriter(r) | 254 | tw, err := newTransferWriter(r1) |
4487 | 219 | if err != nil { | 255 | if err != nil { |
4488 | 220 | return err | 256 | return err |
4489 | 221 | } | 257 | } |
4490 | @@ -230,8 +266,19 @@ | |||
4491 | 230 | return err | 266 | return err |
4492 | 231 | } | 267 | } |
4493 | 232 | 268 | ||
4494 | 269 | // contentLengthAlreadySent may have been already sent for | ||
4495 | 270 | // POST/PUT requests, even if zero length. See Issue 8180. | ||
4496 | 271 | contentLengthAlreadySent := tw.shouldSendContentLength() | ||
4497 | 272 | if r1.ContentLength == 0 && !chunked(r1.TransferEncoding) && !contentLengthAlreadySent { | ||
4498 | 273 | if _, err := io.WriteString(w, "Content-Length: 0\r\n"); err != nil { | ||
4499 | 274 | return err | ||
4500 | 275 | } | ||
4501 | 276 | } | ||
4502 | 277 | |||
4503 | 233 | // End-of-header | 278 | // End-of-header |
4505 | 234 | io.WriteString(w, "\r\n") | 279 | if _, err := io.WriteString(w, "\r\n"); err != nil { |
4506 | 280 | return err | ||
4507 | 281 | } | ||
4508 | 235 | 282 | ||
4509 | 236 | // Write body and trailer | 283 | // Write body and trailer |
4510 | 237 | err = tw.WriteBody(w) | 284 | err = tw.WriteBody(w) |
4511 | 238 | 285 | ||
4512 | === modified file 'http13client/response_test.go' | |||
4513 | --- http13client/response_test.go 2014-03-19 23:13:58 +0000 | |||
4514 | +++ http13client/response_test.go 2014-06-20 13:02:58 +0000 | |||
4515 | @@ -30,6 +30,10 @@ | |||
4516 | 30 | return &Request{Method: method} | 30 | return &Request{Method: method} |
4517 | 31 | } | 31 | } |
4518 | 32 | 32 | ||
4519 | 33 | func dummyReq11(method string) *Request { | ||
4520 | 34 | return &Request{Method: method, Proto: "HTTP/1.1", ProtoMajor: 1, ProtoMinor: 1} | ||
4521 | 35 | } | ||
4522 | 36 | |||
4523 | 33 | var respTests = []respTest{ | 37 | var respTests = []respTest{ |
4524 | 34 | // Unchunked response without Content-Length. | 38 | // Unchunked response without Content-Length. |
4525 | 35 | { | 39 | { |
4526 | 36 | 40 | ||
4527 | === modified file 'http13client/responsewrite_test.go' | |||
4528 | --- http13client/responsewrite_test.go 2014-03-19 23:13:58 +0000 | |||
4529 | +++ http13client/responsewrite_test.go 2014-06-20 13:02:58 +0000 | |||
4530 | @@ -27,7 +27,7 @@ | |||
4531 | 27 | ProtoMinor: 0, | 27 | ProtoMinor: 0, |
4532 | 28 | Request: dummyReq("GET"), | 28 | Request: dummyReq("GET"), |
4533 | 29 | Header: http.Header{}, | 29 | Header: http.Header{}, |
4535 | 30 | Body: ioutil.NopCloser(bytes.NewBufferString("abcdef")), | 30 | Body: ioutil.NopCloser(strings.NewReader("abcdef")), |
4536 | 31 | ContentLength: 6, | 31 | ContentLength: 6, |
4537 | 32 | }, | 32 | }, |
4538 | 33 | 33 | ||
4539 | @@ -50,6 +50,106 @@ | |||
4540 | 50 | "\r\n" + | 50 | "\r\n" + |
4541 | 51 | "abcdef", | 51 | "abcdef", |
4542 | 52 | }, | 52 | }, |
4543 | 53 | // HTTP/1.1 response with unknown length and Connection: close | ||
4544 | 54 | { | ||
4545 | 55 | Response{ | ||
4546 | 56 | StatusCode: 200, | ||
4547 | 57 | ProtoMajor: 1, | ||
4548 | 58 | ProtoMinor: 1, | ||
4549 | 59 | Request: dummyReq("GET"), | ||
4550 | 60 | Header: http.Header{}, | ||
4551 | 61 | Body: ioutil.NopCloser(strings.NewReader("abcdef")), | ||
4552 | 62 | ContentLength: -1, | ||
4553 | 63 | Close: true, | ||
4554 | 64 | }, | ||
4555 | 65 | "HTTP/1.1 200 OK\r\n" + | ||
4556 | 66 | "Connection: close\r\n" + | ||
4557 | 67 | "\r\n" + | ||
4558 | 68 | "abcdef", | ||
4559 | 69 | }, | ||
4560 | 70 | // HTTP/1.1 response with unknown length and not setting connection: close | ||
4561 | 71 | { | ||
4562 | 72 | Response{ | ||
4563 | 73 | StatusCode: 200, | ||
4564 | 74 | ProtoMajor: 1, | ||
4565 | 75 | ProtoMinor: 1, | ||
4566 | 76 | Request: dummyReq11("GET"), | ||
4567 | 77 | Header: http.Header{}, | ||
4568 | 78 | Body: ioutil.NopCloser(strings.NewReader("abcdef")), | ||
4569 | 79 | ContentLength: -1, | ||
4570 | 80 | Close: false, | ||
4571 | 81 | }, | ||
4572 | 82 | "HTTP/1.1 200 OK\r\n" + | ||
4573 | 83 | "Connection: close\r\n" + | ||
4574 | 84 | "\r\n" + | ||
4575 | 85 | "abcdef", | ||
4576 | 86 | }, | ||
4577 | 87 | // HTTP/1.1 response with unknown length and not setting connection: close, but | ||
4578 | 88 | // setting chunked. | ||
4579 | 89 | { | ||
4580 | 90 | Response{ | ||
4581 | 91 | StatusCode: 200, | ||
4582 | 92 | ProtoMajor: 1, | ||
4583 | 93 | ProtoMinor: 1, | ||
4584 | 94 | Request: dummyReq11("GET"), | ||
4585 | 95 | Header: http.Header{}, | ||
4586 | 96 | Body: ioutil.NopCloser(strings.NewReader("abcdef")), | ||
4587 | 97 | ContentLength: -1, | ||
4588 | 98 | TransferEncoding: []string{"chunked"}, | ||
4589 | 99 | Close: false, | ||
4590 | 100 | }, | ||
4591 | 101 | "HTTP/1.1 200 OK\r\n" + | ||
4592 | 102 | "Transfer-Encoding: chunked\r\n\r\n" + | ||
4593 | 103 | "6\r\nabcdef\r\n0\r\n\r\n", | ||
4594 | 104 | }, | ||
4595 | 105 | // HTTP/1.1 response 0 content-length, and nil body | ||
4596 | 106 | { | ||
4597 | 107 | Response{ | ||
4598 | 108 | StatusCode: 200, | ||
4599 | 109 | ProtoMajor: 1, | ||
4600 | 110 | ProtoMinor: 1, | ||
4601 | 111 | Request: dummyReq11("GET"), | ||
4602 | 112 | Header: http.Header{}, | ||
4603 | 113 | Body: nil, | ||
4604 | 114 | ContentLength: 0, | ||
4605 | 115 | Close: false, | ||
4606 | 116 | }, | ||
4607 | 117 | "HTTP/1.1 200 OK\r\n" + | ||
4608 | 118 | "Content-Length: 0\r\n" + | ||
4609 | 119 | "\r\n", | ||
4610 | 120 | }, | ||
4611 | 121 | // HTTP/1.1 response 0 content-length, and non-nil empty body | ||
4612 | 122 | { | ||
4613 | 123 | Response{ | ||
4614 | 124 | StatusCode: 200, | ||
4615 | 125 | ProtoMajor: 1, | ||
4616 | 126 | ProtoMinor: 1, | ||
4617 | 127 | Request: dummyReq11("GET"), | ||
4618 | 128 | Header: http.Header{}, | ||
4619 | 129 | Body: ioutil.NopCloser(strings.NewReader("")), | ||
4620 | 130 | ContentLength: 0, | ||
4621 | 131 | Close: false, | ||
4622 | 132 | }, | ||
4623 | 133 | "HTTP/1.1 200 OK\r\n" + | ||
4624 | 134 | "Content-Length: 0\r\n" + | ||
4625 | 135 | "\r\n", | ||
4626 | 136 | }, | ||
4627 | 137 | // HTTP/1.1 response 0 content-length, and non-nil non-empty body | ||
4628 | 138 | { | ||
4629 | 139 | Response{ | ||
4630 | 140 | StatusCode: 200, | ||
4631 | 141 | ProtoMajor: 1, | ||
4632 | 142 | ProtoMinor: 1, | ||
4633 | 143 | Request: dummyReq11("GET"), | ||
4634 | 144 | Header: http.Header{}, | ||
4635 | 145 | Body: ioutil.NopCloser(strings.NewReader("foo")), | ||
4636 | 146 | ContentLength: 0, | ||
4637 | 147 | Close: false, | ||
4638 | 148 | }, | ||
4639 | 149 | "HTTP/1.1 200 OK\r\n" + | ||
4640 | 150 | "Connection: close\r\n" + | ||
4641 | 151 | "\r\nfoo", | ||
4642 | 152 | }, | ||
4643 | 53 | // HTTP/1.1, chunked coding; empty trailer; close | 153 | // HTTP/1.1, chunked coding; empty trailer; close |
4644 | 54 | { | 154 | { |
4645 | 55 | Response{ | 155 | Response{ |
4646 | @@ -92,6 +192,22 @@ | |||
4647 | 92 | "Foo: Bar Baz\r\n" + | 192 | "Foo: Bar Baz\r\n" + |
4648 | 93 | "\r\n", | 193 | "\r\n", |
4649 | 94 | }, | 194 | }, |
4650 | 195 | |||
4651 | 196 | // Want a single Content-Length header. Fixing issue 8180 where | ||
4652 | 197 | // there were two. | ||
4653 | 198 | { | ||
4654 | 199 | Response{ | ||
4655 | 200 | StatusCode: http.StatusOK, | ||
4656 | 201 | ProtoMajor: 1, | ||
4657 | 202 | ProtoMinor: 1, | ||
4658 | 203 | Request: &Request{Method: "POST"}, | ||
4659 | 204 | Header: http.Header{}, | ||
4660 | 205 | ContentLength: 0, | ||
4661 | 206 | TransferEncoding: nil, | ||
4662 | 207 | Body: nil, | ||
4663 | 208 | }, | ||
4664 | 209 | "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n", | ||
4665 | 210 | }, | ||
4666 | 95 | } | 211 | } |
4667 | 96 | 212 | ||
4668 | 97 | for i := range respWriteTests { | 213 | for i := range respWriteTests { |
4669 | 98 | 214 | ||
4670 | === modified file 'http13client/server.go' | |||
4671 | --- http13client/server.go 2014-03-19 23:13:58 +0000 | |||
4672 | +++ http13client/server.go 2014-06-20 13:02:58 +0000 | |||
4673 | @@ -10,21 +10,27 @@ | |||
4674 | 10 | "io/ioutil" | 10 | "io/ioutil" |
4675 | 11 | "log" | 11 | "log" |
4676 | 12 | "net" | 12 | "net" |
4677 | 13 | "strings" | ||
4678 | 14 | "sync" | 13 | "sync" |
4679 | 15 | ) | 14 | ) |
4680 | 16 | 15 | ||
4681 | 16 | type eofReaderWithWriteTo struct{} | ||
4682 | 17 | |||
4683 | 18 | func (eofReaderWithWriteTo) WriteTo(io.Writer) (int64, error) { return 0, nil } | ||
4684 | 19 | func (eofReaderWithWriteTo) Read([]byte) (int, error) { return 0, io.EOF } | ||
4685 | 20 | |||
4686 | 17 | // eofReader is a non-nil io.ReadCloser that always returns EOF. | 21 | // eofReader is a non-nil io.ReadCloser that always returns EOF. |
4689 | 18 | // It embeds a *strings.Reader so it still has a WriteTo method | 22 | // It has a WriteTo method so io.Copy won't need a buffer. |
4688 | 19 | // and io.Copy won't need a buffer. | ||
4690 | 20 | var eofReader = &struct { | 23 | var eofReader = &struct { |
4692 | 21 | *strings.Reader | 24 | eofReaderWithWriteTo |
4693 | 22 | io.Closer | 25 | io.Closer |
4694 | 23 | }{ | 26 | }{ |
4696 | 24 | strings.NewReader(""), | 27 | eofReaderWithWriteTo{}, |
4697 | 25 | ioutil.NopCloser(nil), | 28 | ioutil.NopCloser(nil), |
4698 | 26 | } | 29 | } |
4699 | 27 | 30 | ||
4700 | 31 | // Verify that an io.Copy from an eofReader won't require a buffer. | ||
4701 | 32 | var _ io.WriterTo = eofReader | ||
4702 | 33 | |||
4703 | 28 | // loggingConn is used for debugging. | 34 | // loggingConn is used for debugging. |
4704 | 29 | type loggingConn struct { | 35 | type loggingConn struct { |
4705 | 30 | name string | 36 | name string |
4706 | 31 | 37 | ||
4707 | === modified file 'http13client/transfer.go' | |||
4708 | --- http13client/transfer.go 2014-03-19 23:13:58 +0000 | |||
4709 | +++ http13client/transfer.go 2014-06-20 13:02:58 +0000 | |||
4710 | @@ -13,6 +13,7 @@ | |||
4711 | 13 | "io/ioutil" | 13 | "io/ioutil" |
4712 | 14 | "net/http" | 14 | "net/http" |
4713 | 15 | "net/textproto" | 15 | "net/textproto" |
4714 | 16 | "sort" | ||
4715 | 16 | "strconv" | 17 | "strconv" |
4716 | 17 | "strings" | 18 | "strings" |
4717 | 18 | "sync" | 19 | "sync" |
4718 | @@ -144,11 +145,10 @@ | |||
4719 | 144 | return false | 145 | return false |
4720 | 145 | } | 146 | } |
4721 | 146 | 147 | ||
4723 | 147 | func (t *transferWriter) WriteHeader(w io.Writer) (err error) { | 148 | func (t *transferWriter) WriteHeader(w io.Writer) error { |
4724 | 148 | if t.Close { | 149 | if t.Close { |
4728 | 149 | _, err = io.WriteString(w, "Connection: close\r\n") | 150 | if _, err := io.WriteString(w, "Connection: close\r\n"); err != nil { |
4729 | 150 | if err != nil { | 151 | return err |
4727 | 151 | return | ||
4730 | 152 | } | 152 | } |
4731 | 153 | } | 153 | } |
4732 | 154 | 154 | ||
4733 | @@ -156,43 +156,44 @@ | |||
4734 | 156 | // function of the sanitized field triple (Body, ContentLength, | 156 | // function of the sanitized field triple (Body, ContentLength, |
4735 | 157 | // TransferEncoding) | 157 | // TransferEncoding) |
4736 | 158 | if t.shouldSendContentLength() { | 158 | if t.shouldSendContentLength() { |
4741 | 159 | io.WriteString(w, "Content-Length: ") | 159 | if _, err := io.WriteString(w, "Content-Length: "); err != nil { |
4742 | 160 | _, err = io.WriteString(w, strconv.FormatInt(t.ContentLength, 10)+"\r\n") | 160 | return err |
4743 | 161 | if err != nil { | 161 | } |
4744 | 162 | return | 162 | if _, err := io.WriteString(w, strconv.FormatInt(t.ContentLength, 10)+"\r\n"); err != nil { |
4745 | 163 | return err | ||
4746 | 163 | } | 164 | } |
4747 | 164 | } else if chunked(t.TransferEncoding) { | 165 | } else if chunked(t.TransferEncoding) { |
4751 | 165 | _, err = io.WriteString(w, "Transfer-Encoding: chunked\r\n") | 166 | if _, err := io.WriteString(w, "Transfer-Encoding: chunked\r\n"); err != nil { |
4752 | 166 | if err != nil { | 167 | return err |
4750 | 167 | return | ||
4753 | 168 | } | 168 | } |
4754 | 169 | } | 169 | } |
4755 | 170 | 170 | ||
4756 | 171 | // Write Trailer header | 171 | // Write Trailer header |
4757 | 172 | if t.Trailer != nil { | 172 | if t.Trailer != nil { |
4762 | 173 | // TODO: At some point, there should be a generic mechanism for | 173 | keys := make([]string, 0, len(t.Trailer)) |
4759 | 174 | // writing long headers, using HTTP line splitting | ||
4760 | 175 | io.WriteString(w, "Trailer: ") | ||
4761 | 176 | needComma := false | ||
4763 | 177 | for k := range t.Trailer { | 174 | for k := range t.Trailer { |
4764 | 178 | k = http.CanonicalHeaderKey(k) | 175 | k = http.CanonicalHeaderKey(k) |
4765 | 179 | switch k { | 176 | switch k { |
4766 | 180 | case "Transfer-Encoding", "Trailer", "Content-Length": | 177 | case "Transfer-Encoding", "Trailer", "Content-Length": |
4767 | 181 | return &badStringError{"invalid Trailer key", k} | 178 | return &badStringError{"invalid Trailer key", k} |
4768 | 182 | } | 179 | } |
4771 | 183 | if needComma { | 180 | keys = append(keys, k) |
4772 | 184 | io.WriteString(w, ",") | 181 | } |
4773 | 182 | if len(keys) > 0 { | ||
4774 | 183 | sort.Strings(keys) | ||
4775 | 184 | // TODO: could do better allocation-wise here, but trailers are rare, | ||
4776 | 185 | // so being lazy for now. | ||
4777 | 186 | if _, err := io.WriteString(w, "Trailer: "+strings.Join(keys, ",")+"\r\n"); err != nil { | ||
4778 | 187 | return err | ||
4779 | 185 | } | 188 | } |
4780 | 186 | io.WriteString(w, k) | ||
4781 | 187 | needComma = true | ||
4782 | 188 | } | 189 | } |
4783 | 189 | _, err = io.WriteString(w, "\r\n") | ||
4784 | 190 | } | 190 | } |
4785 | 191 | 191 | ||
4787 | 192 | return | 192 | return nil |
4788 | 193 | } | 193 | } |
4789 | 194 | 194 | ||
4791 | 195 | func (t *transferWriter) WriteBody(w io.Writer) (err error) { | 195 | func (t *transferWriter) WriteBody(w io.Writer) error { |
4792 | 196 | var err error | ||
4793 | 196 | var ncopy int64 | 197 | var ncopy int64 |
4794 | 197 | 198 | ||
4795 | 198 | // Write body | 199 | // Write body |
4796 | @@ -229,11 +230,16 @@ | |||
4797 | 229 | 230 | ||
4798 | 230 | // TODO(petar): Place trailer writer code here. | 231 | // TODO(petar): Place trailer writer code here. |
4799 | 231 | if chunked(t.TransferEncoding) { | 232 | if chunked(t.TransferEncoding) { |
4800 | 233 | // Write Trailer header | ||
4801 | 234 | if t.Trailer != nil { | ||
4802 | 235 | if err := t.Trailer.Write(w); err != nil { | ||
4803 | 236 | return err | ||
4804 | 237 | } | ||
4805 | 238 | } | ||
4806 | 232 | // Last chunk, empty trailer | 239 | // Last chunk, empty trailer |
4807 | 233 | _, err = io.WriteString(w, "\r\n") | 240 | _, err = io.WriteString(w, "\r\n") |
4808 | 234 | } | 241 | } |
4811 | 235 | 242 | return err | |
4810 | 236 | return | ||
4812 | 237 | } | 243 | } |
4813 | 238 | 244 | ||
4814 | 239 | type transferReader struct { | 245 | type transferReader struct { |
4815 | @@ -265,6 +271,22 @@ | |||
4816 | 265 | return true | 271 | return true |
4817 | 266 | } | 272 | } |
4818 | 267 | 273 | ||
4819 | 274 | var ( | ||
4820 | 275 | suppressedHeaders304 = []string{"Content-Type", "Content-Length", "Transfer-Encoding"} | ||
4821 | 276 | suppressedHeadersNoBody = []string{"Content-Length", "Transfer-Encoding"} | ||
4822 | 277 | ) | ||
4823 | 278 | |||
4824 | 279 | func suppressedHeaders(status int) []string { | ||
4825 | 280 | switch { | ||
4826 | 281 | case status == 304: | ||
4827 | 282 | // RFC 2616 section 10.3.5: "the response MUST NOT include other entity-headers" | ||
4828 | 283 | return suppressedHeaders304 | ||
4829 | 284 | case !bodyAllowedForStatus(status): | ||
4830 | 285 | return suppressedHeadersNoBody | ||
4831 | 286 | } | ||
4832 | 287 | return nil | ||
4833 | 288 | } | ||
4834 | 289 | |||
4835 | 268 | // msg is *Request or *Response. | 290 | // msg is *Request or *Response. |
4836 | 269 | func readTransfer(msg interface{}, r *bufio.Reader) (err error) { | 291 | func readTransfer(msg interface{}, r *bufio.Reader) (err error) { |
4837 | 270 | t := &transferReader{RequestMethod: "GET"} | 292 | t := &transferReader{RequestMethod: "GET"} |
4838 | @@ -511,7 +533,7 @@ | |||
4839 | 511 | case "Transfer-Encoding", "Trailer", "Content-Length": | 533 | case "Transfer-Encoding", "Trailer", "Content-Length": |
4840 | 512 | return nil, &badStringError{"bad trailer key", key} | 534 | return nil, &badStringError{"bad trailer key", key} |
4841 | 513 | } | 535 | } |
4843 | 514 | trailer.Del(key) | 536 | trailer[key] = nil |
4844 | 515 | } | 537 | } |
4845 | 516 | if len(trailer) == 0 { | 538 | if len(trailer) == 0 { |
4846 | 517 | return nil, nil | 539 | return nil, nil |
4847 | @@ -643,13 +665,23 @@ | |||
4848 | 643 | } | 665 | } |
4849 | 644 | switch rr := b.hdr.(type) { | 666 | switch rr := b.hdr.(type) { |
4850 | 645 | case *Request: | 667 | case *Request: |
4852 | 646 | rr.Trailer = http.Header(hdr) | 668 | mergeSetHeader(&rr.Trailer, http.Header(hdr)) |
4853 | 647 | case *Response: | 669 | case *Response: |
4855 | 648 | rr.Trailer = http.Header(hdr) | 670 | mergeSetHeader(&rr.Trailer, http.Header(hdr)) |
4856 | 649 | } | 671 | } |
4857 | 650 | return nil | 672 | return nil |
4858 | 651 | } | 673 | } |
4859 | 652 | 674 | ||
4860 | 675 | func mergeSetHeader(dst *http.Header, src http.Header) { | ||
4861 | 676 | if *dst == nil { | ||
4862 | 677 | *dst = src | ||
4863 | 678 | return | ||
4864 | 679 | } | ||
4865 | 680 | for k, vv := range src { | ||
4866 | 681 | (*dst)[k] = vv | ||
4867 | 682 | } | ||
4868 | 683 | } | ||
4869 | 684 | |||
4870 | 653 | func (b *body) Close() error { | 685 | func (b *body) Close() error { |
4871 | 654 | b.mu.Lock() | 686 | b.mu.Lock() |
4872 | 655 | defer b.mu.Unlock() | 687 | defer b.mu.Unlock() |
4873 | 656 | 688 | ||
4874 | === modified file 'http13client/transport.go' | |||
4875 | --- http13client/transport.go 2014-03-20 09:26:28 +0000 | |||
4876 | +++ http13client/transport.go 2014-06-20 13:02:58 +0000 | |||
4877 | @@ -110,6 +110,9 @@ | |||
4878 | 110 | // An error is returned if the proxy environment is invalid. | 110 | // An error is returned if the proxy environment is invalid. |
4879 | 111 | // A nil URL and nil error are returned if no proxy is defined in the | 111 | // A nil URL and nil error are returned if no proxy is defined in the |
4880 | 112 | // environment, or a proxy should not be used for the given request. | 112 | // environment, or a proxy should not be used for the given request. |
4881 | 113 | // | ||
4882 | 114 | // As a special case, if req.URL.Host is "localhost" (with or without | ||
4883 | 115 | // a port number), then a nil URL and nil error will be returned. | ||
4884 | 113 | func ProxyFromEnvironment(req *Request) (*url.URL, error) { | 116 | func ProxyFromEnvironment(req *Request) (*url.URL, error) { |
4885 | 114 | proxy := httpProxyEnv.Get() | 117 | proxy := httpProxyEnv.Get() |
4886 | 115 | if proxy == "" { | 118 | if proxy == "" { |
4887 | @@ -161,9 +164,11 @@ | |||
4888 | 161 | // and redirects), see Get, Post, and the Client type. | 164 | // and redirects), see Get, Post, and the Client type. |
4889 | 162 | func (t *Transport) RoundTrip(req *Request) (resp *Response, err error) { | 165 | func (t *Transport) RoundTrip(req *Request) (resp *Response, err error) { |
4890 | 163 | if req.URL == nil { | 166 | if req.URL == nil { |
4891 | 167 | req.closeBody() | ||
4892 | 164 | return nil, errors.New("http: nil Request.URL") | 168 | return nil, errors.New("http: nil Request.URL") |
4893 | 165 | } | 169 | } |
4894 | 166 | if req.Header == nil { | 170 | if req.Header == nil { |
4895 | 171 | req.closeBody() | ||
4896 | 167 | return nil, errors.New("http: nil Request.Header") | 172 | return nil, errors.New("http: nil Request.Header") |
4897 | 168 | } | 173 | } |
4898 | 169 | if req.URL.Scheme != "http" && req.URL.Scheme != "https" { | 174 | if req.URL.Scheme != "http" && req.URL.Scheme != "https" { |
4899 | @@ -174,16 +179,19 @@ | |||
4900 | 174 | } | 179 | } |
4901 | 175 | t.altMu.RUnlock() | 180 | t.altMu.RUnlock() |
4902 | 176 | if rt == nil { | 181 | if rt == nil { |
4903 | 182 | req.closeBody() | ||
4904 | 177 | return nil, &badStringError{"unsupported protocol scheme", req.URL.Scheme} | 183 | return nil, &badStringError{"unsupported protocol scheme", req.URL.Scheme} |
4905 | 178 | } | 184 | } |
4906 | 179 | return rt.RoundTrip(req) | 185 | return rt.RoundTrip(req) |
4907 | 180 | } | 186 | } |
4908 | 181 | if req.URL.Host == "" { | 187 | if req.URL.Host == "" { |
4909 | 188 | req.closeBody() | ||
4910 | 182 | return nil, errors.New("http: no Host in request URL") | 189 | return nil, errors.New("http: no Host in request URL") |
4911 | 183 | } | 190 | } |
4912 | 184 | treq := &transportRequest{Request: req} | 191 | treq := &transportRequest{Request: req} |
4913 | 185 | cm, err := t.connectMethodForRequest(treq) | 192 | cm, err := t.connectMethodForRequest(treq) |
4914 | 186 | if err != nil { | 193 | if err != nil { |
4915 | 194 | req.closeBody() | ||
4916 | 187 | return nil, err | 195 | return nil, err |
4917 | 188 | } | 196 | } |
4918 | 189 | 197 | ||
4919 | @@ -194,6 +202,7 @@ | |||
4920 | 194 | pconn, err := t.getConn(req, cm) | 202 | pconn, err := t.getConn(req, cm) |
4921 | 195 | if err != nil { | 203 | if err != nil { |
4922 | 196 | t.setReqCanceler(req, nil) | 204 | t.setReqCanceler(req, nil) |
4923 | 205 | req.closeBody() | ||
4924 | 197 | return nil, err | 206 | return nil, err |
4925 | 198 | } | 207 | } |
4926 | 199 | 208 | ||
4927 | @@ -231,9 +240,6 @@ | |||
4928 | 231 | t.idleConn = nil | 240 | t.idleConn = nil |
4929 | 232 | t.idleConnCh = nil | 241 | t.idleConnCh = nil |
4930 | 233 | t.idleMu.Unlock() | 242 | t.idleMu.Unlock() |
4931 | 234 | if m == nil { | ||
4932 | 235 | return | ||
4933 | 236 | } | ||
4934 | 237 | for _, conns := range m { | 243 | for _, conns := range m { |
4935 | 238 | for _, pconn := range conns { | 244 | for _, pconn := range conns { |
4936 | 239 | pconn.close() | 245 | pconn.close() |
4937 | @@ -499,12 +505,13 @@ | |||
4938 | 499 | pa := cm.proxyAuth() | 505 | pa := cm.proxyAuth() |
4939 | 500 | 506 | ||
4940 | 501 | pconn := &persistConn{ | 507 | pconn := &persistConn{ |
4947 | 502 | t: t, | 508 | t: t, |
4948 | 503 | cacheKey: cm.key(), | 509 | cacheKey: cm.key(), |
4949 | 504 | conn: conn, | 510 | conn: conn, |
4950 | 505 | reqch: make(chan requestAndChan, 50), | 511 | reqch: make(chan requestAndChan, 1), |
4951 | 506 | writech: make(chan writeRequest, 50), | 512 | writech: make(chan writeRequest, 1), |
4952 | 507 | closech: make(chan struct{}), | 513 | closech: make(chan struct{}), |
4953 | 514 | writeErrCh: make(chan error, 1), | ||
4954 | 508 | } | 515 | } |
4955 | 509 | 516 | ||
4956 | 510 | switch { | 517 | switch { |
4957 | @@ -589,7 +596,7 @@ | |||
4958 | 589 | pconn.conn = tlsConn | 596 | pconn.conn = tlsConn |
4959 | 590 | } | 597 | } |
4960 | 591 | 598 | ||
4962 | 592 | pconn.br = bufio.NewReader(pconn.conn) | 599 | pconn.br = bufio.NewReader(noteEOFReader{pconn.conn, &pconn.sawEOF}) |
4963 | 593 | pconn.bw = bufio.NewWriter(pconn.conn) | 600 | pconn.bw = bufio.NewWriter(pconn.conn) |
4964 | 594 | go pconn.readLoop() | 601 | go pconn.readLoop() |
4965 | 595 | go pconn.writeLoop() | 602 | go pconn.writeLoop() |
4966 | @@ -722,16 +729,22 @@ | |||
4967 | 722 | cacheKey connectMethodKey | 729 | cacheKey connectMethodKey |
4968 | 723 | conn net.Conn | 730 | conn net.Conn |
4969 | 724 | tlsState *tls.ConnectionState | 731 | tlsState *tls.ConnectionState |
4970 | 725 | closed bool // whether conn has been closed | ||
4971 | 726 | br *bufio.Reader // from conn | 732 | br *bufio.Reader // from conn |
4972 | 733 | sawEOF bool // whether we've seen EOF from conn; owned by readLoop | ||
4973 | 727 | bw *bufio.Writer // to conn | 734 | bw *bufio.Writer // to conn |
4974 | 728 | reqch chan requestAndChan // written by roundTrip; read by readLoop | 735 | reqch chan requestAndChan // written by roundTrip; read by readLoop |
4975 | 729 | writech chan writeRequest // written by roundTrip; read by writeLoop | 736 | writech chan writeRequest // written by roundTrip; read by writeLoop |
4977 | 730 | closech chan struct{} // broadcast close when readLoop (TCP connection) closes | 737 | closech chan struct{} // closed when conn closed |
4978 | 731 | isProxy bool | 738 | isProxy bool |
4979 | 739 | // writeErrCh passes the request write error (usually nil) | ||
4980 | 740 | // from the writeLoop goroutine to the readLoop which passes | ||
4981 | 741 | // it off to the res.Body reader, which then uses it to decide | ||
4982 | 742 | // whether or not a connection can be reused. Issue 7569. | ||
4983 | 743 | writeErrCh chan error | ||
4984 | 732 | 744 | ||
4986 | 733 | lk sync.Mutex // guards following 3 fields | 745 | lk sync.Mutex // guards following fields |
4987 | 734 | numExpectedResponses int | 746 | numExpectedResponses int |
4988 | 747 | closed bool // whether conn has been closed | ||
4989 | 735 | broken bool // an error has happened on this connection; marked broken so it's not reused. | 748 | broken bool // an error has happened on this connection; marked broken so it's not reused. |
4990 | 736 | // mutateHeaderFunc is an optional func to modify extra | 749 | // mutateHeaderFunc is an optional func to modify extra |
4991 | 737 | // headers on each outbound request before it's written. (the | 750 | // headers on each outbound request before it's written. (the |
4992 | @@ -739,6 +752,7 @@ | |||
4993 | 739 | mutateHeaderFunc func(http.Header) | 752 | mutateHeaderFunc func(http.Header) |
4994 | 740 | } | 753 | } |
4995 | 741 | 754 | ||
4996 | 755 | // isBroken reports whether this connection is in a known broken state. | ||
4997 | 742 | func (pc *persistConn) isBroken() bool { | 756 | func (pc *persistConn) isBroken() bool { |
4998 | 743 | pc.lk.Lock() | 757 | pc.lk.Lock() |
4999 | 744 | b := pc.broken | 758 | b := pc.broken |
5000 | @@ -763,7 +777,6 @@ |
The diff has been truncated for viewing.