Commit Graph

33 Commits

Author SHA1 Message Date
Pulkit Goyal
07314d0686 py3: convert the mode argument of os.fdopen to unicodes (1 of 2)
os.fdopen() does not accepts bytes as its second argument which represent the
mode in which the file is to be opened. This patch makes sure unicodes are
passed in py3 by using pycompat.sysstr().
2017-02-13 20:06:38 +05:30
Gregory Szorc
e1840d5435 httppeer: advertise and support application/mercurial-0.2
Now that servers expose a capability indicating they support
application/mercurial-0.2 and compression, clients can key off
this to say they support responses that are compressed with
various compression formats.

After this commit, the HTTP wire protocol client now sends an
"X-HgProto-<N>" request header indicating its support for
"application/mercurial-0.2" media type and various compression
formats.

This commit also implements support for handling
"application/mercurial-0.2" responses. It simply reads the header
compression engine identifier then routes the remainder of the
response to the appropriate decompressor.

There were some test changes, but only to logging. That points to
an obvious gap in our test coverage. This will be addressed in a
subsequent commit once server support is in place (it is hard to
test without server support).
2016-12-24 15:22:18 -07:00
Gregory Szorc
52ab84abd8 httppeer: extract code for HTTP header spanning
A second consumer of HTTP header spanning will soon be introduced.
Factor out the code to do this so it can be reused.
2016-12-24 14:46:02 -07:00
Gregory Szorc
a071fc938c httppeer: assign Vary request header last
In preparation for adding another value to it in a subsequent patch.

While I was here, I added some empty lines because walls of text
are hard to read.
2016-11-28 21:07:51 -08:00
Gregory Szorc
825ca90158 httppeer: document why super() isn't used
Adding a follow-up to document lack of super() per Augie's
request.
2016-11-21 20:12:51 -08:00
Augie Fackler
05fae84175 httppeer: drop an except block that says it happens only on Python 2.3 2016-11-21 17:47:11 -05:00
Gregory Szorc
037fb7f520 httppeer: use compression engine API for decompressing responses
In preparation for supporting multiple compression formats on the
wire protocol, we need all users of the wire protocol to use
compression engine APIs.

This commit ports the HTTP wire protocol client to use the
compression engine API.

The code for handling the HTTPException is a bit hacky. Essentially,
HTTPException could be thrown by any read() from the socket. However,
as part of porting the API, we no longer have a generator wrapping
the socket and we don't have a single place where we can trap the
exception. We solve this by introducing a proxy class that intercepts
read() and converts the exception appropriately.

In the future, we could introduce a new compression engine API that
supports emitting a generator of decompressed chunks. This would
eliminate the need for the proxy class. As I said when I introduced
the decompressorreader() API, I'm not fond of it and would support
transitioning to something better. This can be done as a follow-up,
preferably once all the code is using the compression engine API and
we have a better idea of the API needs of all the consumers.
2016-11-20 13:55:53 -08:00
Gregory Szorc
b47fc17304 httppeer: do decompression inside _callstream
The current HTTP transport protocol only compresses certain command
responses and requires calls to that command to call
"_callcompressable," which zlib decompresses the response
transparently.

Upcoming changes will enable *any* response to be compressed with
varying compression formats. In order to handle this better, this
commit moves the decompression bits to the main function performing
the HTTP request. We introduce an underscore-prefixed argument to
denote this behavior so it doesn't conflict with a named argument
to a command.
2016-11-19 18:31:40 -08:00
Mads Kiilerich
40ab99f130 httppeer: make __del__ access to self.urlopener more safe
Some errors could in some cases show unfortunate scary and confusing warnings
from the httppeer delstructors:

  abort: nodename nor servname provided, or not known
  Exception AttributeError: "'httpspeer' object has no attribute 'urlopener'" in <bound method httpspeer.__del__ of <mercurial.httppeer.httpspeer object at 0x106e1f5d0>> ignored```

To mute that, take 8bdb0bb8e209 to the next level and use getattr in __del__.
2016-10-31 13:43:48 +01:00
Pulkit Goyal
af9d7f66d0 py3: conditionalize httplib import
The httplib library is renamed to http.client in python 3. So the
import is conditionalized and a test is added in check-code to warn
to use util.httplib
2016-06-28 16:01:53 +05:30
FUJIWARA Katsunori
b93088d0e1 httppeer: make a message translatable
This message has been overlooked by check-code, because it starts with
non-alphabet character ('(').

Making this message translatable seems reasonable, because exception
message below in same function is already translatable

  - 'cannot create new http repository'

This is also a part of preparation for making "missing _() in ui
message" detection of check-code more exact.
2016-05-26 01:57:34 +09:00
timeless
109fcbc79e pycompat: switch to util.urlreq/util.urlerr for py3 compat 2016-04-06 23:22:12 +00:00
Martin von Zweigbergk
4cc86f7b27 bundle: move writebundle() from changegroup.py to bundle2.py (API)
writebundle() writes a bundle2 bundle or a plain changegroup1. Imagine
away the "2" in "bundle2.py" for a moment and this change should makes
sense. The bundle wraps the changegroup, so it makes sense that it
knows about it. Another sign that this is correct is that the delayed
import of bundle2 in changegroup goes away.

I'll leave it for another time to remove the "2" in "bundle2.py"
(alternatively, extract a new bundle.py from it).
2016-03-28 14:41:29 -07:00
Augie Fackler
b3f8347d29 http: support sending hgargs via POST body instead of in GET or headers
narrowhg (for its narrow spec) and remotefilelog (for its large batch
requests) would like to be able to make requests with argument sets so
absurdly large that they blow out total request size limit on some
http servers. As a workaround, support stuffing args at the start
of the POST body.

We will probably want to leave this behavior off by default in servers
forever, because it makes the old "POSTs are only for writes"
assumption wrong, which might break some of the simpler authentication
configurations.
2016-03-11 11:37:00 -05:00
Augie Fackler
a5ee58fab0 httppeer: compute header names only once
This also helps make the code a little more readable.
2016-03-11 11:51:22 -05:00
Augie Fackler
892d18bb0e httppeer: indent existing argument handling with if True
I'm about to add another case, so it makes sense to split this out to make the
semantic changes in the next change more obvious.
2016-03-11 11:33:43 -05:00
Augie Fackler
e4394d072a httppeer: move size computation later in _callstream
A future change will alter some of the arg-sending logic in a way that matters
for request body size. Centralizing the logic now will make later patches
easier to review.
2016-03-11 11:26:12 -05:00
Augie Fackler
f7dec33abe httppeer: do less splitting on httpheader value
We only care about the first value split off, so only split off the first
value.
2016-03-11 11:24:50 -05:00
timeless
ebb1d48658 cleanup: remove superfluous space after space after equals (python) 2015-12-31 08:16:59 +00:00
Pierre-Yves David
30913031d4 error: get Abort from 'error' instead of 'util'
The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be
confused about that and gives all the credit to 'util' instead of the
hardworking 'error'. In a spirit of equity, we break the cycle of injustice and
give back to 'error' the respect it deserves. And screw that 'util' poser.

For great justice.
2015-10-08 12:55:45 -07:00
Gregory Szorc
13fd37af77 httppeer: use absolute_import 2015-08-08 19:35:28 -07:00
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07:00
Kyle Lippincott
e4209444cf httppeer: allow extensions to replace urllib2.Request
The authentication library my extension wants to use requires using a different
opener and a different request builder.  This change pulls the call to
urllib2.Request out so that my extension can replace it just like it can
replace urlopener.
2015-06-08 16:55:21 -07:00
Matt Mackall
350e314a71 httppeer: use try/except/finally 2015-05-15 09:57:02 -05:00
Eric Sumner
7cbcf9bdca changegroup.writebundle: provide ui
The next diff will add support for writing bundle2 files to writebundle, but
the bundle2 generator wants access to a ui object.  This changes the signature
and callsites to pass one in.
2015-01-15 14:39:41 -08:00
Matt Harbison
e8e311feb1 httppeer: close the temporary bundle file after two-way streaming it
This fixes several push tests in test-bundle2-exchange.t that were failing on
Windows with messages like the following:

   $ hg -R main push http://localhost:$HGPORT2/ -r 32af7686d403 \
        --bookmark book_32af
   pushing to http://localhost:$HGPORT2/
   searching for changes
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
   remote: 1 new obsolescence markers
   updating bookmark book_32af
   abort: The process cannot access the file because it is being used by another
            process: 'C:\path\to\tmp\bundle.hg'
   [255]
2014-10-25 21:34:49 -04:00
Mads Kiilerich
8b72c846ed httppeer: reintroduce _abort that accidentally was removed in fc14a1cf743e
Including the missing test coverage that would have caught it.
2014-04-23 23:29:55 +02:00
Pierre-Yves David
c21b92af91 httppeer: support for _calltwowaystream
This new method is now supported by http too.
2014-04-15 17:53:52 -04:00
Pierre-Yves David
e3dee4d3e4 wireproto: drop the _decompress method in favor a new call type
We already have multiple call function for multiple return type. The
`_decompress` function is only used for http and seems like a layer violation.
We drop it in favor of a new call type dedicated to "stream that may be useful to
compress".
2014-03-28 14:24:13 -07:00
Matt Mackall
8091c8a1c3 httppeer: improve protocol check
Pre-0.6c hgweb used text/plain for protocol responses. This meant
that a web server could serve a static file and confuse a client into
generating a nasty traceback.

Now we insist that text/plain protocol responses not include a
Content-Length, which older hgweb didn't generate but will typically
be produced for static files.
2013-02-17 14:34:53 -06:00
Matt Mackall
a4ec314909 httppeer: avoid large dumps when we don't see an hgweb repo
When we don't get an hgweb protocol response, we dump the response to
the user for diagnostic purposes (it might be a cgitb message, for
instance).

But if we try to clone a bundle, we don't want to show the
entire bundle in the error message. Also, we don't want fetch the
full bundle multiple times during fallback. So we only fetch 1k here.
2013-02-17 14:41:31 -06:00
Pierre-Yves.David@ens-lyon.org
2c6293bccf httprepo: ensure Content-Type header exists when pushing data
Otherwise the wireprotocol just hangs while trying to send data. (And
nothing is received at the other side)
2012-07-13 13:21:20 +02:00
Peter Arrenbrecht
ef7b77046e peer: introduce real peer classes
This change separates peer implementations from the repository implementation.
localpeer currently is a simple pass-through to localrepository, except for
legacy calls, which have already been removed from localpeer. This ensures that
the local client code only uses the most modern peer API when talking to local
repos.

Peers have a .local() method which returns either None or the underlying
localrepository (or descendant thereof). Repos have a .peer() method to return
a freshly constructed localpeer. The latter is used by hg.peer(), and also to
allow folks to pass either a peer or a repo to some generic helper methods.
We might want to get rid of .peer() eventually.

The only user of locallegacypeer is debugdiscovery, which uses it to pose as a
pre-setdiscovery client. But we decided to leave the old API defined in
locallegacypeer for clarity and maybe for other uses in the future.

It might be nice to actually define the peer API directly in peer.py as stub
methods. One problem there is, however, that localpeer implements
lock/addchangegroup, whereas the true remote peers implement unbundle.
It might be desireable to get rid of this distinction eventually.
2012-07-13 21:47:06 +02:00