@@ -690,8 +690,7 @@ func (c *Client) do(req *Request) (retres *Response, reterr error) {
690
690
stripSensitiveHeaders = true
691
691
}
692
692
}
693
- copyHeaders (req , stripSensitiveHeaders )
694
-
693
+ copyHeaders (req , stripSensitiveHeaders , ! includeBody )
695
694
// Add the Referer header from the most recent
696
695
// request URL to the new one, if it's not https->http:
697
696
if ref := refererForURL (reqs [len (reqs )- 1 ].URL , req .URL , req .Header .Get ("Referer" )); ref != "" {
@@ -758,7 +757,7 @@ func (c *Client) do(req *Request) (retres *Response, reterr error) {
758
757
// makeHeadersCopier makes a function that copies headers from the
759
758
// initial Request, ireq. For every redirect, this function must be called
760
759
// so that it can copy headers into the upcoming Request.
761
- func (c * Client ) makeHeadersCopier (ireq * Request ) func (req * Request , stripSensitiveHeaders bool ) {
760
+ func (c * Client ) makeHeadersCopier (ireq * Request ) func (req * Request , stripSensitiveHeaders , stripBodyHeaders bool ) {
762
761
// The headers to copy are from the very initial request.
763
762
// We use a closured callback to keep a reference to these original headers.
764
763
var (
@@ -772,7 +771,7 @@ func (c *Client) makeHeadersCopier(ireq *Request) func(req *Request, stripSensit
772
771
}
773
772
}
774
773
775
- return func (req * Request , stripSensitiveHeaders bool ) {
774
+ return func (req * Request , stripSensitiveHeaders , stripBodyHeaders bool ) {
776
775
// If Jar is present and there was some initial cookies provided
777
776
// via the request header, then we may need to alter the initial
778
777
// cookies as we follow redirects since each redirect may end up
@@ -810,12 +809,21 @@ func (c *Client) makeHeadersCopier(ireq *Request) func(req *Request, stripSensit
810
809
// (at least the safe ones).
811
810
for k , vv := range ireqhdr {
812
811
sensitive := false
812
+ body := false
813
813
switch CanonicalHeaderKey (k ) {
814
814
case "Authorization" , "Www-Authenticate" , "Cookie" , "Cookie2" ,
815
815
"Proxy-Authorization" , "Proxy-Authenticate" :
816
816
sensitive = true
817
+
818
+ case "Content-Encoding" , "Content-Language" , "Content-Location" ,
819
+ "Content-Type" :
820
+ // Headers relating to the body which is removed for
821
+ // POST to GET redirects
822
+ // https://fetch.spec.whatwg.org/#http-redirect-fetch
823
+ body = true
824
+
817
825
}
818
- if ! (sensitive && stripSensitiveHeaders ) {
826
+ if ! (sensitive && stripSensitiveHeaders ) && ! ( body && stripBodyHeaders ) {
819
827
req .Header [k ] = vv
820
828
}
821
829
}
0 commit comments