Mercurial > public > mercurial-scm > hg-stable
diff mercurial/url.py @ 37048:a708e1e4d7a8
url: support suppressing Accept header
Sending this header automatically could interfere with future
testing and client behavior. Let's add a knob to disable the
behavior.
We don't have a control for User-Agent because urllib will send
it if we don't set something. I don't feel like hacking into the
bowels of urllib to figure out how to suppress that. UA shouldn't
be used for anything meaningful. So it shouldn't pose any problems
beyond non-determinism (since the header has the Mercurial version in
it).
Differential Revision: https://phab.mercurial-scm.org/D2843
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 13 Mar 2018 10:34:36 -0700 |
parents | 02221d6fb041 |
children | f0b6fbea00cf |
line wrap: on
line diff
--- a/mercurial/url.py Tue Mar 13 11:20:07 2018 -0700 +++ b/mercurial/url.py Tue Mar 13 10:34:36 2018 -0700 @@ -494,7 +494,7 @@ handlerfuncs = [] def opener(ui, authinfo=None, useragent=None, loggingfh=None, - loggingname=b's', loggingopts=None): + loggingname=b's', loggingopts=None, sendaccept=True): ''' construct an opener suitable for urllib2 authinfo will be added to the password manager @@ -506,6 +506,9 @@ ``loggingname`` denotes the name of the to print when logging. ``loggingopts`` is a dict of keyword arguments to pass to the constructed ``util.socketobserver`` instance. + + ``sendaccept`` allows controlling whether the ``Accept`` request header + is sent. The header is sent by default. ''' handlers = [] @@ -562,7 +565,9 @@ # been sent on all requests since forever. We keep sending it for backwards # compatibility reasons. Modern versions of the wire protocol use # X-HgProto-<N> for advertising client support. - opener.addheaders.append((r'Accept', r'application/mercurial-0.1')) + if sendaccept: + opener.addheaders.append((r'Accept', r'application/mercurial-0.1')) + return opener def open(ui, url_, data=None):