drain request body for connection reuse (#6)

This commit is contained in:
Paul Meyer
2016-06-17 12:47:12 -07:00
committed by Christopher Boumenot
parent e0b63eb299
commit 686fb24c00

View File

@@ -3,6 +3,7 @@ package ntlmssp
import ( import (
"bytes" "bytes"
"encoding/base64" "encoding/base64"
"io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
) )
@@ -50,6 +51,7 @@ func (l Negotiator) RoundTrip(req *http.Request) (res *http.Response, err error)
if !resauth.IsNegotiate() { if !resauth.IsNegotiate() {
// Unauthorized, Negotiate not requested, let's try with basic auth // Unauthorized, Negotiate not requested, let's try with basic auth
req.Header.Set("Authorization", string(reqauth)) req.Header.Set("Authorization", string(reqauth))
io.Copy(ioutil.Discard, res.Body)
res.Body.Close() res.Body.Close()
req.Body = ioutil.NopCloser(bytes.NewReader(body.Bytes())) req.Body = ioutil.NopCloser(bytes.NewReader(body.Bytes()))
@@ -65,6 +67,7 @@ func (l Negotiator) RoundTrip(req *http.Request) (res *http.Response, err error)
if resauth.IsNegotiate() { if resauth.IsNegotiate() {
// 401 with request:Basic and response:Negotiate // 401 with request:Basic and response:Negotiate
io.Copy(ioutil.Discard, res.Body)
res.Body.Close() res.Body.Close()
// recycle credentials // recycle credentials
@@ -93,6 +96,7 @@ func (l Negotiator) RoundTrip(req *http.Request) (res *http.Response, err error)
// Negotiation failed, let client deal with response // Negotiation failed, let client deal with response
return res, nil return res, nil
} }
io.Copy(ioutil.Discard, res.Body)
res.Body.Close() res.Body.Close()
// send authenticate // send authenticate