Mercurial > hg
annotate tests/test-url-download.t @ 37048:fc5e261915b9
wireproto: require POST for all HTTPv2 requests
Wire protocol version 1 transfers argument data via request
headers by default. This has historically caused problems because
servers institute limits on the length of individual HTTP headers
as well as the total size of all request headers. Mercurial servers
can advertise the maximum length of an individual header. But
there's no guarantee any intermediate HTTP agents will accept
headers up to that length.
In the existing wire protocol, server operators typically also
key off the HTTP request method to implement authentication.
For example, GET requests translate to read-only requests and
can be allowed. But read-write commands must use POST and require
authentication. This has typically worked because the only wire
protocol commands that use POST modify the repo (e.g. the
"unbundle" command).
There is an experimental feature to enable clients to transmit
argument data via POST request bodies. This is technically a
better and more robust solution. But we can't enable it by default
because of servers assuming POST means write access.
In version 2 of the wire protocol, the permissions of a request
are encoded in the URL. And with it being a new protocol in a new
URL space, we're not constrained by backwards compatibility
requirements.
This commit adopts the technically superior mechanism of using
HTTP request bodies to send argument data by requiring POST for
all commands. Strictly speaking, it may be possible to send
request bodies on GET requests. But my experience is that not all
HTTP stacks support this. POST pretty much always works. Using POST
for read-only operations does sacrifice some RESTful design
purity. But this API cares about practicality, not about being
in Roy T. Fielding's REST ivory tower.
There's a chance we may relax this restriction in the future. But
for now, I want to see how far we can get with a POST only API.
Differential Revision: https://phab.mercurial-scm.org/D2837
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 13 Mar 2018 11:57:43 -0700 |
parents | 05d415790761 |
children | 8214c71589f6 |
rev | line source |
---|---|
35562
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1 #require serve |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3 $ hg init server |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
4 $ hg serve -R server -p $HGPORT -d --pid-file=hg1.pid -E ../error.log |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
5 $ cat hg1.pid >> $DAEMON_PIDS |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
6 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
7 Check basic fetching |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
8 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
9 $ hg debugdownload "http://localhost:$HGPORT/?cmd=lookup&key=tip" |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
10 1 0000000000000000000000000000000000000000 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
11 $ hg debugdownload -o null.txt "http://localhost:$HGPORT/?cmd=lookup&key=null" |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
12 $ cat null.txt |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
13 1 0000000000000000000000000000000000000000 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
14 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
15 Check the request is made from the usual Mercurial logic |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
16 (rev details, give different content if the request has a Mercurial user agent) |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
17 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
18 $ get-with-headers.py --headeronly "localhost:$HGPORT" "rev/tip" content-type |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
19 200 Script output follows |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
20 content-type: text/html; charset=ascii |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
21 $ hg debugdownload "http://localhost:$HGPORT/rev/tip" |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
22 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
23 # HG changeset patch |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
24 # User |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
25 # Date 0 0 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
26 # Node ID 0000000000000000000000000000000000000000 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
27 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
28 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
29 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
30 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
31 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
32 Check other kind of compatible url |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
33 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
34 $ hg debugdownload ./null.txt |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
35 1 0000000000000000000000000000000000000000 |
6580cf751418
debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
36 |
35564
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
37 Test largefile URL |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
38 ------------------ |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
39 |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
40 $ cat << EOF >> $HGRCPATH |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
41 > [extensions] |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
42 > largefiles= |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
43 > EOF |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
44 |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
45 $ killdaemons.py |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
46 $ rm -f error.log hg1.pid |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
47 $ hg serve -R server -p $HGPORT -d --pid-file=hg1.pid -E error.log |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
48 $ cat hg1.pid >> $DAEMON_PIDS |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
49 |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
50 $ hg -R server debuglfput null.txt |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
51 a57b57b39ee4dc3da1e03526596007f480ecdbe8 |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
52 |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
53 $ hg --traceback debugdownload "largefile://a57b57b39ee4dc3da1e03526596007f480ecdbe8" --config paths.default=http://localhost:$HGPORT/ |
cf841f2b5a72
largefiles: add support for 'largefiles://' url scheme
Boris Feld <boris.feld@octobus.net>
parents:
35562
diff
changeset
|
54 1 0000000000000000000000000000000000000000 |
35730
05d415790761
debugdownload: read repository hgrc if there is one
Boris Feld <boris.feld@octobus.net>
parents:
35564
diff
changeset
|
55 |
05d415790761
debugdownload: read repository hgrc if there is one
Boris Feld <boris.feld@octobus.net>
parents:
35564
diff
changeset
|
56 from within a repository |
05d415790761
debugdownload: read repository hgrc if there is one
Boris Feld <boris.feld@octobus.net>
parents:
35564
diff
changeset
|
57 |
05d415790761
debugdownload: read repository hgrc if there is one
Boris Feld <boris.feld@octobus.net>
parents:
35564
diff
changeset
|
58 $ hg clone http://localhost:$HGPORT/ client |
05d415790761
debugdownload: read repository hgrc if there is one
Boris Feld <boris.feld@octobus.net>
parents:
35564
diff
changeset
|
59 no changes found |
05d415790761
debugdownload: read repository hgrc if there is one
Boris Feld <boris.feld@octobus.net>
parents:
35564
diff
changeset
|
60 updating to branch default |
05d415790761
debugdownload: read repository hgrc if there is one
Boris Feld <boris.feld@octobus.net>
parents:
35564
diff
changeset
|
61 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
05d415790761
debugdownload: read repository hgrc if there is one
Boris Feld <boris.feld@octobus.net>
parents:
35564
diff
changeset
|
62 |
05d415790761
debugdownload: read repository hgrc if there is one
Boris Feld <boris.feld@octobus.net>
parents:
35564
diff
changeset
|
63 $ cd client |
05d415790761
debugdownload: read repository hgrc if there is one
Boris Feld <boris.feld@octobus.net>
parents:
35564
diff
changeset
|
64 $ hg path |
05d415790761
debugdownload: read repository hgrc if there is one
Boris Feld <boris.feld@octobus.net>
parents:
35564
diff
changeset
|
65 default = http://localhost:$HGPORT/ |
05d415790761
debugdownload: read repository hgrc if there is one
Boris Feld <boris.feld@octobus.net>
parents:
35564
diff
changeset
|
66 $ hg debugdownload "largefile://a57b57b39ee4dc3da1e03526596007f480ecdbe8" |
05d415790761
debugdownload: read repository hgrc if there is one
Boris Feld <boris.feld@octobus.net>
parents:
35564
diff
changeset
|
67 1 0000000000000000000000000000000000000000 |
05d415790761
debugdownload: read repository hgrc if there is one
Boris Feld <boris.feld@octobus.net>
parents:
35564
diff
changeset
|
68 $ cd .. |