comparison mercurial/url.py @ 35439:e7bb5fc4570c

lfs: add git to the User-Agent header for blob transfers As we were trying to transition off of the non production lfs-test-server for further experimenting, one of the problems we ran into was interoperability. A coworker setup gitbucket[1] to act as the blob server, tested with git, and passed it off to me. But push failed with a message saying "abort: LFS server returns invalid JSON:", and then proceeded to dump a huge HTML page to the screen. It turns out that it is assuming that git is the only thing that wants to do a blob transfer, and everything else is a web browser wanting HTML. It's only a single data point, but I suspect other things may be doing this too. RFC7231 gives an example [2] of listing multiple products in decreasing order of significance. Since the standard provides for this, and since it works with the one problematic server I found, I'm just enabling this by default for a better UX. There's nothing significant about the version of git chosen, other than it is the current version. [1] https://github.com/gitbucket/gitbucket/ [2] https://tools.ietf.org/html/rfc7231#page-46
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 14 Dec 2017 13:04:08 -0500
parents 2976cf87a60a
children 37a1501cbcfd
comparison
equal deleted inserted replaced
35438:0ebd94ac56d1 35439:e7bb5fc4570c
464 464
465 return request 465 return request
466 466
467 handlerfuncs = [] 467 handlerfuncs = []
468 468
469 def opener(ui, authinfo=None): 469 def opener(ui, authinfo=None, useragent=None):
470 ''' 470 '''
471 construct an opener suitable for urllib2 471 construct an opener suitable for urllib2
472 authinfo will be added to the password manager 472 authinfo will be added to the password manager
473 ''' 473 '''
474 # experimental config: ui.usehttp2 474 # experimental config: ui.usehttp2
510 # The "(Mercurial %s)" string contains the distribution 510 # The "(Mercurial %s)" string contains the distribution
511 # name and version. Other client implementations should choose their 511 # name and version. Other client implementations should choose their
512 # own distribution name. Since servers should not be using the user 512 # own distribution name. Since servers should not be using the user
513 # agent string for anything, clients should be able to define whatever 513 # agent string for anything, clients should be able to define whatever
514 # user agent they deem appropriate. 514 # user agent they deem appropriate.
515 agent = 'mercurial/proto-1.0 (Mercurial %s)' % util.version() 515 #
516 opener.addheaders = [(r'User-agent', pycompat.sysstr(agent))] 516 # The custom user agent is for lfs, because unfortunately some servers
517 # do look at this value.
518 if not useragent:
519 agent = 'mercurial/proto-1.0 (Mercurial %s)' % util.version()
520 opener.addheaders = [(r'User-agent', pycompat.sysstr(agent))]
521 else:
522 opener.addheaders = [(r'User-agent', pycompat.sysstr(useragent))]
517 523
518 # This header should only be needed by wire protocol requests. But it has 524 # This header should only be needed by wire protocol requests. But it has
519 # been sent on all requests since forever. We keep sending it for backwards 525 # been sent on all requests since forever. We keep sending it for backwards
520 # compatibility reasons. Modern versions of the wire protocol use 526 # compatibility reasons. Modern versions of the wire protocol use
521 # X-HgProto-<N> for advertising client support. 527 # X-HgProto-<N> for advertising client support.