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