wireprotoserver: document and improve the httplib workaround
This workaround dates all the way back to
a42d27bc809d in 2008.
The code is esoteric enough to warrant an inline explanation.
So I've added one.
At the time the code was written, the only wire protocol command
that accepted an HTTP request body was "unbundle." In the years
since, we've grown the ability to accept command arguments via
HTTP POST requests. So, the code has been changed to apply the
httplib workaround to all HTTP POST requests.
While staring at this code, I realized that the HTTP response
body in case of error is always the same. And, it appears to
mimic the behavior of a failed call to the "unbundle" command.
Since we can hit this code path on theoretically any protocol
request (since self.check_perm accepts custom auth checking
functions which may raise), I'm having a hard time believing
that clients react well to an "unbundle" response payload on
any wire protocol command. I wouldn't be surprised if our test
coverage for this feature only covers HTTP POST calls to
"unbundle." In other words, the experimental support for sending
arguments via HTTP POST request bodies may result in badness on
the client. Something to investigate another time perhaps...
Differential Revision: https://phab.mercurial-scm.org/D2064
wireprotoserver: move error response handling out of hgweb
The exception handler for ErrorResponse has more to do with the
wire protocol than the generic HTTP server. Move the code so it
lives alongside other wire protocol code.
Differential Revision: https://phab.mercurial-scm.org/D2021
hgweb: move call to protocol handler outside of try..except
The protocol handler doesn't raise ErrorResponse. So it doesn't
need to be in this `try..except ErrorResponse` block.
Differential Revision: https://phab.mercurial-scm.org/D2020
wireprotoserver: move protocol parsing and dispatch out of hgweb
Previously, hgweb_mod had code for detecting if the request
was for the wire protocol. It would then (eventually) call
wireprotoserver.callhttp() to dispatch the request handling.
Detection of wire protocol requests is not trivial. There's
currently a big gotcha in the handling of the "cmd" request
parameter, for example.
Furthermore, in the near future we will have a second HTTP
protocol handler. Its mechanism for calling commands will be
a bit different. And we don't want the low-level logic for
detecting protocol commands to live in hgweb.
We establish a new function in wireprotoserver for detecting
an HTTP protocol request and for giving the caller an easy-to-use
mechanism for dispatching requests to it.
Some wire protocol specific functionality still lives in hgweb.
This will be addressed in subsequent commits.
Differential Revision: https://phab.mercurial-scm.org/D2019
largefiles: register wire protocol commands with modern APIs
The wireproto.wireprotocommand decorator is the preferred mechanism for
registering wire protocol commands. In addition, wireproto.commands
is no longer a 2-tuple and use of that 2-tuple API should be considered
deprecated.
This commit ports largefiles to use wireproto.wireprotocommand()
and ports to the "commandentry" API.
As part of this, the definition of the "lheads" wire protocol
command is moved to the proper stanza.
We stop short of actually using wireprotocommand as a decorator
in order to minimize churn. We should ideally move wire protocol
commands to the registrar mechanism. But that's for another
changeset.
Differential Revision: https://phab.mercurial-scm.org/D2018
wireproto: function for testing if wire protocol command is available
Currently, we perform simple membership testing for whether a wire
command is available. In the future, not all wire protocol commands
will be available on all transports. For example, a legacy transport
may not support newer commands.
In preparation of this, teach the protocol handlers to call into a
function to determine if a wire protocol command is available. That
function currently does membership testing like before, so behavior
should be identical.
In the case of the HTTP server, behavior is a bit wonkier. "cmd" is
used by both the wire protocol and hgweb. We do want the protocol
handler to handle requests for all commands that look like wire
protocol commands, even if they aren't available. Otherwise, the
fallback to hgweb would only confuse automated clients and make it
easier for hgweb to accidentally implement a "cmd" that is identical
to wire protocol commands (since they aren't centrally registered).
Differential Revision: https://phab.mercurial-scm.org/D1999