Mercurial > hg
view tests/common-pattern.py @ 36426:23d12524a202
http: drop custom http client logic
Eight and a half years ago, as my starter bug on code.google.com, I
investigated a mysterious "broken pipe" error from seemingly random
clients[0]. That investigation revealed a tragic story: the Python
standard library's httplib was (and remains) barely functional. During
large POSTs, if a server responds early with an error (even a
permission denied error!) the client only notices that the server
closed the connection and everything breaks. Such server behavior is
implicitly legal under RFC 2616 (the latest HTTP RFC as of when I was
last working on this), and my understanding is that later RFCs have
made it explicitly legal to respond early with any status code outside
the 2xx range.
I embarked, probably foolishly, on a journey to write a new http
library with better overall behavior. The http library appears to work
well in most cases, but it can get confused in the presence of
proxies, and it depends on select(2) which limits its utility if a lot
of file descriptors are open. I haven't touched the http library in
almost two years, and in the interim the Python community has
discovered a better way[1] of writing network code. In theory some day
urllib3 will have its own home-grown http library built on h11[2], or
we could do that. Either way, it's time to declare our current
confusingly-named "http2" client logic and move on. I do hope to
revisit this some day: it's still garbage that we can't even respond
with a 401 or 403 without reading the entire POST body from the
client, but the goalposts on writing a new http client library have
moved substantially. We're almost certainly better off just switching
to requests and eventually picking up their http fixes than trying to
live with something that realistically only we'll ever use. Another
approach would be to write an adapter so that Mercurial can use pycurl
if it's installed. Neither of those approaches seem like they should
be investigated prior to a release of Mercurial that works on Python
3: that's where the mindshare is going to be for any improvements to
the state of the http client art.
0: http://web.archive.org/web/20130501031801/http://code.google.com/p/support/issues/detail?id=2716
1: http://sans-io.readthedocs.io/
2: https://github.com/njsmith/h11
Differential Revision: https://phab.mercurial-scm.org/D2444
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 25 Feb 2018 23:51:32 -0500 |
parents | 003ae586a02e |
children | 03368431f014 |
line wrap: on
line source
# common patterns in test at can safely be replaced from __future__ import absolute_import import os substitutions = [ # list of possible compressions (br'(zstd,)?zlib,none,bzip2', br'$USUAL_COMPRESSIONS$' ), (br'=(zstd,)?zlib', br'=$BUNDLE2_COMPRESSIONS$' ), # capabilities sent through http (br'bundlecaps=HG20%2Cbundle2%3DHG20%250A' br'bookmarks%250A' br'changegroup%253D01%252C02%250A' br'digests%253Dmd5%252Csha1%252Csha512%250A' br'error%253Dabort%252Cunsupportedcontent%252Cpushraced%252Cpushkey%250A' br'hgtagsfnodes%250A' br'listkeys%250A' br'phases%253Dheads%250A' br'pushkey%250A' br'remote-changegroup%253Dhttp%252Chttps%250A' br'stream%253Dv2', # (the replacement patterns) br'$USUAL_BUNDLE_CAPS$' ), (br'bundlecaps=HG20%2Cbundle2%3DHG20%250A' br'bookmarks%250A' br'changegroup%253D01%252C02%250A' br'digests%253Dmd5%252Csha1%252Csha512%250A' br'error%253Dabort%252Cunsupportedcontent%252Cpushraced%252Cpushkey%250A' br'hgtagsfnodes%250A' br'listkeys%250A' br'phases%253Dheads%250A' br'pushkey%250A' br'remote-changegroup%253Dhttp%252Chttps', # (the replacement patterns) br'$USUAL_BUNDLE_CAPS_SERVER$' ), # bundle2 capabilities sent through ssh (br'bundle2=HG20%0A' br'bookmarks%0A' br'changegroup%3D01%2C02%0A' br'digests%3Dmd5%2Csha1%2Csha512%0A' br'error%3Dabort%2Cunsupportedcontent%2Cpushraced%2Cpushkey%0A' br'hgtagsfnodes%0A' br'listkeys%0A' br'phases%3Dheads%0A' br'pushkey%0A' br'remote-changegroup%3Dhttp%2Chttps%0A' br'stream%3Dv2', # (replacement patterns) br'$USUAL_BUNDLE2_CAPS$' ), # bundle2 capabilities advertised by the server (br'bundle2=HG20%0A' br'bookmarks%0A' br'changegroup%3D01%2C02%0A' br'digests%3Dmd5%2Csha1%2Csha512%0A' br'error%3Dabort%2Cunsupportedcontent%2Cpushraced%2Cpushkey%0A' br'hgtagsfnodes%0A' br'listkeys%0A' br'phases%3Dheads%0A' br'pushkey%0A' br'remote-changegroup%3Dhttp%2Chttps', # (replacement patterns) br'$USUAL_BUNDLE2_CAPS_SERVER$' ), # HTTP log dates (br' - - \[\d\d/.../2\d\d\d \d\d:\d\d:\d\d] "(GET|PUT|POST)', lambda m: br' - - [$LOGDATE$] "' + m.group(1) ), # Windows has an extra '/' in the following lines that get globbed away: # pushing to file:/*/$TESTTMP/r2 (glob) # comparing with file:/*/$TESTTMP/r2 (glob) # sub/maybelarge.dat: largefile 34..9c not available from # file:/*/$TESTTMP/largefiles-repo (glob) (br'(.*file:/)/?(/\$TESTTMP.*)', lambda m: m.group(1) + b'*' + m.group(2) + b' (glob)' ), ] # Various platform error strings, keyed on a common replacement string _errors = { br'$ENOENT$': ( # strerror() br'No such file or directory', # FormatMessage(ERROR_FILE_NOT_FOUND) br'The system cannot find the file specified', ), br'$ENOTDIR$': ( # strerror() br'Not a directory', # FormatMessage(ERROR_PATH_NOT_FOUND) br'The system cannot find the path specified', ), br'$ECONNRESET$': ( # strerror() br'Connection reset by peer', # FormatMessage(WSAECONNRESET) br'An existing connection was forcibly closed by the remote host', ), br'$EADDRINUSE$': ( # strerror() br'Address already in use', # FormatMessage(WSAEADDRINUSE) br'Only one usage of each socket address' br' \(protocol/network address/port\) is normally permitted', ), } for replace, msgs in _errors.items(): substitutions.extend((m, replace) for m in msgs) # Output lines on Windows that can be autocorrected for '\' vs '/' path # differences. _winpathfixes = [ # cloning subrepo s\ss from $TESTTMP/t/s/ss # cloning subrepo foo\bar from http://localhost:$HGPORT/foo/bar br'(?m)^cloning subrepo \S+\\.*', # pulling from $TESTTMP\issue1852a br'(?m)^pulling from \$TESTTMP\\.*', # pushing to $TESTTMP\a br'(?m)^pushing to \$TESTTMP\\.*', # pushing subrepo s\ss to $TESTTMP/t/s/ss br'(?m)^pushing subrepo \S+\\\S+ to.*', # moving d1\d11\a1 to d3/d11/a1 br'(?m)^moving \S+\\.*', # d1\a: not recording move - dummy does not exist br'\S+\\\S+: not recording move .+', # reverting s\a br'(?m)^reverting (?!subrepo ).*\\.*', # saved backup bundle to # $TESTTMP\test\.hg\strip-backup/443431ffac4f-2fc5398a-backup.hg br'(?m)^saved backup bundle to \$TESTTMP.*\.hg', # no changes made to subrepo s\ss since last push to ../tcc/s/ss br'(?m)^no changes made to subrepo \S+\\\S+ since.*', # changeset 5:9cc5aa7204f0: stuff/maybelarge.dat references missing # $TESTTMP\largefiles-repo-hg\.hg\largefiles\76..38 br'(?m)^changeset .* references (corrupted|missing) \$TESTTMP\\.*', # stuff/maybelarge.dat: largefile 76..38 not available from # file:/*/$TESTTMP\largefiles-repo (glob) br'.*: largefile \S+ not available from file:/\*/.+', ] if os.name == 'nt': substitutions.extend([(s, lambda match: match.group().replace(b'\\', b'/')) for s in _winpathfixes])