net/http: redirection and headers

162 views
Skip to first unread message

Robert Obryk

unread,
Jun 24, 2013, 10:31:22 PM6/24/13
to golang-nuts
I've noticed that whenever http.Client follows a redirection it issues
all subsequent requests without headers specified in the first
request. I wasn't able to find anything in the RFC that would mandate
such behaviour, nor does it seem sensible to me (for instance, Accept*
and Range headers get dropped). Why doesn't it just leave preexisting
headers alone?

Cheers,
Robert

David DENG

unread,
Jun 24, 2013, 10:52:21 PM6/24/13
to golan...@googlegroups.com
I think you can customize the http.Client.CheckRedirect function to get what you need.

David

Robert

unread,
Jun 25, 2013, 4:12:55 AM6/25/13
to golan...@googlegroups.com
On Tuesday, 25 June 2013 04:52:21 UTC+2, David DENG wrote:
I think you can customize the http.Client.CheckRedirect function to get what you need.
The documentation doesn't state whether CheckRedirect can modify the request, so that's unsupported at best. I'd also like to understand when the current is at all useful: I can't imagine why one'd want additional headers to get dropped.

Robert
Message has been deleted

Robert Obryk

unread,
Jun 25, 2013, 8:24:08 AM6/25/13
to Islan Dberry, golang-nuts
On Tue, Jun 25, 2013 at 2:19 PM, Islan Dberry <islan...@ymail.com> wrote:
> Cookie headers should be dropped.
Thanks. Actually, Cookie headers are handled separately there: they
are retrieved from the cookie jar for each URL we get redirected to in
turn, so they are handled mostly properly now.

Is there a canonical way of finding out which headers should be
dropped? I couldn't find any mention of required behaviour when
redirecting in the RFC.

Robert
Reply all
Reply to author
Forward
Message has been deleted
0 new messages