[PATCH] url: add distribution and version to user-agent request header (BC)
Augie Fackler
raf at durin42.com
Thu Jul 14 13:48:59 EDT 2016
On Wed, Jul 13, 2016 at 10:18:26PM -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1468473406 25200
> # Wed Jul 13 22:16:46 2016 -0700
> # Node ID 6ad61d5001b1fbfebf317d0557f158d4b34a0772
> # Parent 52433f89f816e21ca992ac8c4a41cba0345f1b73
> url: add distribution and version to user-agent request header (BC)
It's actually intentional that we don't advertise hg version in either
direction to my recollection. That said, I have been meaning to write
a patch like this (but with it behind a config knob) so that big
companies can track how many versions of hg are in use. Can you do a
v2 with this off by default behind a config knob?
>
> As a server operator, I've always wanted to know what Mercurial
> version clients are running. Unfortunately, there is no easy
> way to discern this today: the best you can do is sniff capabilities
> from getbundle commands and those aren't updated frequently enough
> to tell you anything that interesting.
>
> This patch adds the distribution name and version to the user-agent
> HTTP request header. We choose "Mercurial" for the distribution
> name because that seems appropriate. The version string comes
> from __version__. It should have no spaces and should therefore be
> safe to include outside of quotes, parenthesis, etc.
>
> Flagging the patch as BC so it shows up in release notes. This
> change should be backwards compatible. But I'm sure there is a server
> operator somewhere filtering on the existing user-agent request
> header. So I want to make noise about this change.
>
> diff --git a/mercurial/url.py b/mercurial/url.py
> --- a/mercurial/url.py
> +++ b/mercurial/url.py
> @@ -500,18 +500,22 @@ def opener(ui, authinfo=None):
> ui.debug('http auth: user %s, password %s\n' %
> (user, passwd and '*' * len(passwd) or 'not set'))
>
> handlers.extend((httpbasicauthhandler(passmgr),
> httpdigestauthhandler(passmgr)))
> handlers.extend([h(ui, passmgr) for h in handlerfuncs])
> opener = urlreq.buildopener(*handlers)
>
> - # 1.0 here is the _protocol_ version
> - opener.addheaders = [('User-agent', 'mercurial/proto-1.0')]
> + opener.addheaders = [('User-agent',
> + # 1.0 here is the _protocol_ version
> + # "Mercurial/%s" identifies the distribution name
> + # and version. Other implementations of the client
> + # should choose a different name.
> + 'mercurial/proto-1.0 Mercurial/%s' % util.version())]
> opener.addheaders.append(('Accept', 'application/mercurial-0.1'))
> return opener
>
> def open(ui, url_, data=None):
> u = util.url(url_)
> if u.scheme:
> u.scheme = u.scheme.lower()
> url_, authinfo = u.authinfo()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list