diff --git a/http_auth.go b/http_auth.go index bfe1736..ce701ac 100644 --- a/http_auth.go +++ b/http_auth.go @@ -20,15 +20,16 @@ package twitter import ( - "net/http" + "bufio" + "bytes" "encoding/base64" + "fmt" "io" - "strings" + "io/ioutil" "net" - "bufio" - "fmt" - "bytes" + "net/http" "net/url" + "strings" ) type readClose struct { @@ -109,7 +110,23 @@ func authPost(url_, user, pwd, client, clientURL, version, agent, bodyType strin body io.Reader) (r *http.Response, err error) { var req http.Request req.Method = "POST" - req.Body = body.(io.ReadCloser) + + var ok bool + req.Body, ok = body.(io.ReadCloser) + if !ok && body != nil { + req.Body = ioutil.NopCloser(body) + } + + if body != nil { + switch v := body.(type) { + case *bytes.Buffer: + req.ContentLength = int64(v.Len()) + case *bytes.Reader: + req.ContentLength = int64(v.Len()) + case *strings.Reader: + req.ContentLength = int64(v.Len()) + } + } h := make(http.Header) h.Add("Content-Type", bodyType)