-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
Related with the issue #244
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -770,9 +770,24 @@ func doRequestFollowRedirects(req *Request, dst []byte, url string, c clientDoer | |
resp.keepBodyBuffer = true | ||
oldBody := bodyBuf.B | ||
bodyBuf.B = dst | ||
scheme := req.uri.Scheme() | ||
req.schemaUpdate = false | ||
|
||
redirectsCount := 0 | ||
for { | ||
// In case redirect to different scheme | ||
if redirectsCount > 0 && !bytes.Equal(scheme, req.uri.Scheme()) { | ||
if strings.HasPrefix(url, string(strHTTPS)) { | ||
req.isTLS = true | ||
req.uri.SetSchemeBytes(strHTTPS) | ||
} else { | ||
req.isTLS = false | ||
req.uri.SetSchemeBytes(strHTTP) | ||
} | ||
scheme = req.uri.Scheme() | ||
req.schemaUpdate = true | ||
} | ||
|
||
req.parsedURI = false | ||
req.Header.host = req.Header.host[:0] | ||
req.SetRequestURI(url) | ||
|
@@ -1068,6 +1083,16 @@ func (c *HostClient) doNonNilReqResp(req *Request, resp *Response) (bool, error) | |
// so the GC may reclaim these resources (e.g. response body). | ||
resp.Reset() | ||
|
||
// If we detected a redirect to another schema | ||
if req.schemaUpdate { | ||
c.IsTLS = bytes.Equal(req.URI().Scheme(), strHTTPS) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
c.Addr = addMissingPort(string(req.Host()), c.IsTLS) | ||
This comment has been minimized.
Sorry, something went wrong.
valyala
Owner
|
||
c.addrIdx = 0 | ||
This comment has been minimized.
Sorry, something went wrong.
valyala
Owner
|
||
c.addrs = nil | ||
req.schemaUpdate = false | ||
req.SetConnectionClose() | ||
} | ||
|
||
cc, err := c.acquireConn() | ||
if err != nil { | ||
return false, err | ||
|
This is awful change:
HostClient
maps insideClient
. There are two maps there:m
is for http HostClientsms
is for https HostClientsThis may update http HostClient to https, while it still remains inside
m
map, so all the future requests to the given http host will go to https.HostClient.IsTLS
, which may be used by concurrent goroutines, i.e. this is racy change.