indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
Sending this header automatically could interfere with future
testing and client behavior. Let's add a knob to disable the
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
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
+ ``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'))
+ # Don't send default headers when in raw mode. This allows us to
+ # bypass most of the behavior of our URL handling code so we can
+ # have near complete control over what's sent on the wire.
+ if opts['peer'] == 'raw':
+ openerargs[r'sendaccept'] = False
opener = urlmod.opener(ui, authinfo, **openerargs)