Show More
@@ -0,0 +1,102 b'' | |||
|
1 | #require serve | |
|
2 | ||
|
3 | Some tests for hgweb responding to HEAD requests | |
|
4 | ||
|
5 | $ hg init test | |
|
6 | $ cd test | |
|
7 | $ mkdir da | |
|
8 | $ echo foo > da/foo | |
|
9 | $ echo foo > foo | |
|
10 | $ hg ci -Ambase | |
|
11 | adding da/foo | |
|
12 | adding foo | |
|
13 | $ hg bookmark -r0 '@' | |
|
14 | $ hg bookmark -r0 'a b c' | |
|
15 | $ hg bookmark -r0 'd/e/f' | |
|
16 | $ hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log | |
|
17 | $ cat hg.pid >> $DAEMON_PIDS | |
|
18 | ||
|
19 | manifest | |
|
20 | ||
|
21 | $ get-with-headers.py localhost:$HGPORT --method=HEAD 'file/tip/?style=raw' - date etag server | |
|
22 | 200 Script output follows | |
|
23 | content-type: text/plain; charset=ascii | |
|
24 | ||
|
25 | $ get-with-headers.py localhost:$HGPORT --method=HEAD 'file/tip/da?style=raw' - date etag server | |
|
26 | 200 Script output follows | |
|
27 | content-type: text/plain; charset=ascii | |
|
28 | ||
|
29 | ||
|
30 | plain file | |
|
31 | ||
|
32 | $ get-with-headers.py localhost:$HGPORT --method=HEAD 'file/tip/foo?style=raw' - date etag server | |
|
33 | 200 Script output follows | |
|
34 | content-disposition: inline; filename="foo" | |
|
35 | content-length: 4 | |
|
36 | content-type: application/binary | |
|
37 | ||
|
38 | ||
|
39 | should give a 404 - static file that does not exist | |
|
40 | ||
|
41 | $ get-with-headers.py localhost:$HGPORT --method=HEAD 'static/bogus' - date etag server | |
|
42 | 404 Not Found | |
|
43 | content-type: text/html; charset=ascii | |
|
44 | ||
|
45 | [1] | |
|
46 | ||
|
47 | should give a 404 - bad revision | |
|
48 | ||
|
49 | $ get-with-headers.py localhost:$HGPORT --method=HEAD 'file/spam/foo?style=raw' - date etag server | |
|
50 | 404 Not Found | |
|
51 | content-type: text/plain; charset=ascii | |
|
52 | ||
|
53 | [1] | |
|
54 | ||
|
55 | should give a 400 - bad command | |
|
56 | ||
|
57 | $ get-with-headers.py localhost:$HGPORT --method=HEAD 'file/tip/foo?cmd=spam&style=raw' - date etag server | |
|
58 | 400* (glob) | |
|
59 | content-type: text/plain; charset=ascii | |
|
60 | ||
|
61 | [1] | |
|
62 | ||
|
63 | should give a 404 - file does not exist | |
|
64 | ||
|
65 | $ get-with-headers.py localhost:$HGPORT --method=HEAD 'file/tip/bork?style=raw' - date etag server | |
|
66 | 404 Not Found | |
|
67 | content-type: text/plain; charset=ascii | |
|
68 | ||
|
69 | [1] | |
|
70 | ||
|
71 | try bad style | |
|
72 | ||
|
73 | $ get-with-headers.py localhost:$HGPORT --method=HEAD 'file/tip/?style=foobar' - date etag server | |
|
74 | 200 Script output follows | |
|
75 | content-type: text/html; charset=ascii | |
|
76 | ||
|
77 | ||
|
78 | log | |
|
79 | ||
|
80 | $ get-with-headers.py localhost:$HGPORT --method=HEAD 'log?style=raw' - date etag server | |
|
81 | 200 Script output follows | |
|
82 | content-type: text/plain; charset=ascii | |
|
83 | ||
|
84 | ||
|
85 | access bookmarks | |
|
86 | ||
|
87 | $ get-with-headers.py localhost:$HGPORT --method=HEAD 'rev/@?style=paper' - date etag server | |
|
88 | 200 Script output follows | |
|
89 | content-type: text/html; charset=ascii | |
|
90 | ||
|
91 | ||
|
92 | static file | |
|
93 | ||
|
94 | $ get-with-headers.py localhost:$HGPORT --method=HEAD 'static/style-gitweb.css' - date etag server | |
|
95 | 200 Script output follows | |
|
96 | content-length: 9074 | |
|
97 | content-type: text/css | |
|
98 | ||
|
99 | ||
|
100 | $ killdaemons.py | |
|
101 | ||
|
102 | $ cd .. |
@@ -1,7 +1,7 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | |
|
3 |
"""This does HTTP |
|
|
4 | a subset of the headers plus the body of the result.""" | |
|
3 | """This does HTTP requests (GET by default) given a host:port and path and | |
|
4 | returns a subset of the headers plus the body of the result.""" | |
|
5 | 5 | |
|
6 | 6 | |
|
7 | 7 | import argparse |
@@ -39,6 +39,7 b' parser.add_argument(' | |||
|
39 | 39 | 'value is <header>=<value>', |
|
40 | 40 | ) |
|
41 | 41 | parser.add_argument('--bodyfile', help='Write HTTP response body to a file') |
|
42 | parser.add_argument('--method', default='GET', help='HTTP method to use') | |
|
42 | 43 | parser.add_argument('host') |
|
43 | 44 | parser.add_argument('path') |
|
44 | 45 | parser.add_argument('show', nargs='*') |
@@ -54,7 +55,7 b' requestheaders = args.requestheader' | |||
|
54 | 55 | tag = None |
|
55 | 56 | |
|
56 | 57 | |
|
57 | def request(host, path, show): | |
|
58 | def request(method, host, path, show): | |
|
58 | 59 | assert not path.startswith('/'), path |
|
59 | 60 | global tag |
|
60 | 61 | headers = {} |
@@ -68,7 +69,7 b' def request(host, path, show):' | |||
|
68 | 69 | headers[key] = value |
|
69 | 70 | |
|
70 | 71 | conn = httplib.HTTPConnection(host) |
|
71 |
conn.request( |
|
|
72 | conn.request(method, '/' + path, None, headers) | |
|
72 | 73 | response = conn.getresponse() |
|
73 | 74 | stdout.write( |
|
74 | 75 | b'%d %s\n' % (response.status, response.reason.encode('ascii')) |
@@ -121,9 +122,9 b' def request(host, path, show):' | |||
|
121 | 122 | return response.status |
|
122 | 123 | |
|
123 | 124 | |
|
124 | status = request(args.host, args.path, args.show) | |
|
125 | status = request(args.method, args.host, args.path, args.show) | |
|
125 | 126 | if twice: |
|
126 | status = request(args.host, args.path, args.show) | |
|
127 | status = request(args.method, args.host, args.path, args.show) | |
|
127 | 128 | |
|
128 | 129 | if 200 <= status <= 305: |
|
129 | 130 | sys.exit(0) |
General Comments 0
You need to be logged in to leave comments.
Login now