Merge lp:~jameinel/goose/transfer-content-length-1124561 into lp:goose
Status: | Merged |
---|---|
Approved by: | John A Meinel |
Approved revision: | 98 |
Merged at revision: | 97 |
Proposed branch: | lp:~jameinel/goose/transfer-content-length-1124561 |
Merge into: | lp:goose |
Diff against target: |
120 lines (+52/-7) 2 files modified
http/client.go (+1/-0) http/client_test.go (+51/-7) |
To merge this branch: | bzr merge lp:~jameinel/goose/transfer-content-length-1124561 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+170976@code.launchpad.net |
Commit message
http/client: Set Content-Length
The net/http.Request object takes a Reader
so you have to set ContentLength as an attribute
or it will not set in in the POST request.
Fixes bug #1124561.
Oddly enough, we always buffer everything anyway,
(probably to handle retries?). I would have thought
for at least BinaryRequest we would have not
touched the io.Reader that we got.
Description of the change
http/client: Set Content-Length
The net/http.Request object takes a Reader
so you have to set ContentLength as an attribute
or it will not set in in the POST request.
Fixes bug #1124561.
Oddly enough, we always buffer everything anyway,
(probably to handle retries?). I would have thought
for at least BinaryRequest we would have not
touched the io.Reader that we got.
Reviewers: mp+170976_ code.launchpad. net,
Message:
Please take a look.
Description:
http/client: Set Content-Length
The net/http.Request object takes a Reader
so you have to set ContentLength as an attribute
or it will not set in in the POST request.
Fixes bug #1124561.
Oddly enough, we always buffer everything anyway,
(probably to handle retries?). I would have thought
for at least BinaryRequest we would have not
touched the io.Reader that we got.
https:/ /code.launchpad .net/~jameinel/ goose/transfer- content- length- 1124561/ +merge/ 170976
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/10465043/
Affected files:
A [revision details]
M http/client.go
M http/client_test.go
Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>
Index: http/client.go Header. Add(header, value)
=== modified file 'http/client.go'
--- http/client.go 2013-04-19 09:19:53 +0000
+++ http/client.go 2013-06-23 07:53:30 +0000
@@ -209,6 +209,7 @@
req.
}
}
+ req.ContentLength = int64(len(reqData))
resp, err = c.Do(req)
if err != nil {
return nil, errors.Newf(err, "failed executing the request %s", URL)
Index: http/client_test.go test.go'
=== modified file 'http/client_
--- http/client_test.go 2013-02-22 00:36:43 +0000
+++ http/client_test.go 2013-06-23 07:53:30 +0000
@@ -1,6 +1,9 @@
package http
import ( net/gocheck" net/goose/ testing/ httpsuite" Header{ "Foo": []string{"Bar"}, "Content-Type": gooseAgent( )}})
+ "bytes"
+ "fmt"
+ "io/ioutil"
. "launchpad.
"launchpad.
"net/http"
@@ -52,21 +55,27 @@
http.
contentTypes, "Accept": contentTypes, "User-Agent": []string{
}
-func (s *HTTPClientTest Suite) setupLoopbackRe quest() (*http.Header, Suite) setupLoopbackRe quest() (*http.Header, iter, req *http.Request) { ReadAll( req.Body) Header( ).Add(" Content- Length" , "0") WriteHeader( http.StatusNoCo ntent) Write([ ]byte{} ) HandleFunc( "/", handler)
*Client) {
+func (s *HTTPClientTest
*string, *Client) {
headers := http.Header{}
+ emptyBody := "<no-response-yet>"
+ body := &emptyBody
handler := func(resp http.ResponseWr
headers = req.Header
+ bodyBytes, _ := ioutil.
+ content := string(bodyBytes)
+ *body = content
+ req.Body.Close()
resp.
resp.
resp.
}
s.Mux.
client := New()
- return &headers, client
+ return &headers, body, client
}
func (s *HTTPClientTest Suite) TestBinaryReque stSetsUserAgent (c *C) { Request( ) Request( ) ExpectedStatus: []int{http. StatusNoContent }} BinaryRequest( "POST", s.Server.URL, "", req, nil)
- headers, client := s.setupLoopback
+ headers, _, client := s.setupLoopback
req := &RequestData{
err := client.
c.Assert(err, IsNil)
@@ -76,7 +85,7 @@
}
func (s *HTTPClientTest Suite) TestJSONRequest SetsUserAgent( c *C) { Request( ) Request( ) ExpectedStatus: []int{http.Statu...
- headers, client := s.setupLoopback
+ headers, _, client := s.setupLoopback
req := &RequestData{