Mercurial > hg
annotate mercurial/hgweb/server.py @ 50317:af776c3d5c3e stable
debugdeltachain: stop summing the same chain over and over
Before this patch, delta chain size was computed from scratch for each chain,
disregarding the fact very likely already computed the same of length-1 prefix
for another revisions.
We not cache delta chain size and shortcut the computation when we see them.
Just for my mercurial-devel clone, this move the computation from about 17.5
second to about 4.8 seconds.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 21 Mar 2023 15:44:38 +0000 |
parents | a3c856e2ea2f |
children | 6be6406a2988 |
rev | line source |
---|---|
2391
d351a3be3371
Fixing up comment headers for split up code.
Eric Hopper <hopper@omnifarious.org>
parents:
2355
diff
changeset
|
1 # hgweb/server.py - The standalone hg web server. |
131 | 2 # |
238
3b92f8fe47ae
hgweb.py: kill #! line, clean up copyright notice
mpm@selenic.com
parents:
222
diff
changeset
|
3 # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents:
45046
diff
changeset
|
4 # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com> |
131 | 5 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8224
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
10263 | 7 # GNU General Public License version 2 or any later version. |
131 | 8 |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
26848
diff
changeset
|
9 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
26848
diff
changeset
|
10 import errno |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
26848
diff
changeset
|
11 import os |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
26848
diff
changeset
|
12 import socket |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
26848
diff
changeset
|
13 import sys |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
26848
diff
changeset
|
14 import traceback |
36803
8e1556ac01bb
hgweb: validate WSGI environment dict
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36802
diff
changeset
|
15 import wsgiref.validate |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
26848
diff
changeset
|
16 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
26848
diff
changeset
|
17 from ..i18n import _ |
43089
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43085
diff
changeset
|
18 from ..pycompat import ( |
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43085
diff
changeset
|
19 getattr, |
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43085
diff
changeset
|
20 open, |
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43085
diff
changeset
|
21 ) |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
26848
diff
changeset
|
22 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
26848
diff
changeset
|
23 from .. import ( |
34706
8782076874f5
hgweb: fix logging to use native strings as appropriate
Augie Fackler <augie@google.com>
parents:
34700
diff
changeset
|
24 encoding, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
26848
diff
changeset
|
25 error, |
30639
d524c88511a7
py3: replace os.name with pycompat.osname (part 1 of 2)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30264
diff
changeset
|
26 pycompat, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
26848
diff
changeset
|
27 util, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
26848
diff
changeset
|
28 ) |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46819
diff
changeset
|
29 from ..utils import ( |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46819
diff
changeset
|
30 urlutil, |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46819
diff
changeset
|
31 ) |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
26848
diff
changeset
|
32 |
29566
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29555
diff
changeset
|
33 httpservermod = util.httpserver |
29433
33770d2b6cf9
py3: conditionalize SocketServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28883
diff
changeset
|
34 socketserver = util.socketserver |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
27046
diff
changeset
|
35 urlerr = util.urlerr |
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
27046
diff
changeset
|
36 urlreq = util.urlreq |
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
27046
diff
changeset
|
37 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
38 from . import common |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
39 |
138 | 40 |
2355
eb08fb4d41e1
Splitting up hgweb so it's easier to change.
Eric Hopper <hopper@omnifarious.org>
parents:
2328
diff
changeset
|
41 def _splitURI(uri): |
17427
57c6c24b9bc4
improve some comments and docstrings, fixing issues found when spell checking
Mads Kiilerich <mads@kiilerich.com>
parents:
17424
diff
changeset
|
42 """Return path and query that has been split from uri |
2123
c0729a7f6f8a
Fixed path handling of the standalone server, fixed typo.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
2122
diff
changeset
|
43 |
c0729a7f6f8a
Fixed path handling of the standalone server, fixed typo.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
2122
diff
changeset
|
44 Just like CGI environment, the path is unquoted, the query is |
c0729a7f6f8a
Fixed path handling of the standalone server, fixed typo.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
2122
diff
changeset
|
45 not. |
c0729a7f6f8a
Fixed path handling of the standalone server, fixed typo.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
2122
diff
changeset
|
46 """ |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
47 if '?' in uri: |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
48 path, query = uri.split('?', 1) |
2123
c0729a7f6f8a
Fixed path handling of the standalone server, fixed typo.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
2122
diff
changeset
|
49 else: |
34700
8e5132ece156
hgweb: more native string treatment in query string parsing
Augie Fackler <augie@google.com>
parents:
34645
diff
changeset
|
50 path, query = uri, r'' |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
27046
diff
changeset
|
51 return urlreq.unquote(path), query |
2123
c0729a7f6f8a
Fixed path handling of the standalone server, fixed typo.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
2122
diff
changeset
|
52 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
53 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48906
diff
changeset
|
54 class _error_logger: |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
55 def __init__(self, handler): |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
56 self.handler = handler |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
57 |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
58 def flush(self): |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
59 pass |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
60 |
3130
2e043c9a38a6
hgweb: fix errors spotted by pychecker
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3079
diff
changeset
|
61 def write(self, str): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
62 self.writelines(str.split(b'\n')) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
63 |
3130
2e043c9a38a6
hgweb: fix errors spotted by pychecker
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3079
diff
changeset
|
64 def writelines(self, seq): |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
65 for msg in seq: |
43503
313e3a279828
cleanup: remove pointless r-prefixes on double-quoted strings
Augie Fackler <augie@google.com>
parents:
43457
diff
changeset
|
66 self.handler.log_error("HG error: %s", encoding.strfromlocal(msg)) |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
67 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
68 |
29566
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29555
diff
changeset
|
69 class _httprequesthandler(httpservermod.basehttprequesthandler): |
4870
8f430b1b3025
Make hg serve set the wsgi.url_scheme property correctly.
Wesley J. Landaker <wjl@icecavern.net>
parents:
4868
diff
changeset
|
70 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
71 url_scheme = b'http' |
4957
cdd33a048289
removed trailing whitespace
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4871
diff
changeset
|
72 |
12783
191d0fd5c2fd
hgweb: refactor all pyOpenSSL references into one class
Mads Kiilerich <mads@kiilerich.com>
parents:
12740
diff
changeset
|
73 @staticmethod |
29553
cd3e58862cab
hgweb: pass ui into preparehttpserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29433
diff
changeset
|
74 def preparehttpserver(httpserver, ui): |
12783
191d0fd5c2fd
hgweb: refactor all pyOpenSSL references into one class
Mads Kiilerich <mads@kiilerich.com>
parents:
12740
diff
changeset
|
75 """Prepare .socket of new HTTPServer instance""" |
191d0fd5c2fd
hgweb: refactor all pyOpenSSL references into one class
Mads Kiilerich <mads@kiilerich.com>
parents:
12740
diff
changeset
|
76 |
2355
eb08fb4d41e1
Splitting up hgweb so it's easier to change.
Eric Hopper <hopper@omnifarious.org>
parents:
2328
diff
changeset
|
77 def __init__(self, *args, **kargs): |
34512
482d6f6dba91
hgweb: when constructing or adding to a wsgi environ dict, use native strs
Augie Fackler <augie@google.com>
parents:
34376
diff
changeset
|
78 self.protocol_version = r'HTTP/1.1' |
29566
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29555
diff
changeset
|
79 httpservermod.basehttprequesthandler.__init__(self, *args, **kargs) |
1498
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
80 |
5549
f2f42262adbd
hgweb.server: flush log files after every access
Patrick Mezard <pmezard@gmail.com>
parents:
5150
diff
changeset
|
81 def _log_any(self, fp, format, *args): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
82 fp.write( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
83 pycompat.sysbytes( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
84 r"%s - - [%s] %s" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
85 % ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
86 self.client_address[0], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
87 self.log_date_time_string(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
88 format % args, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
89 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
90 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
91 + b'\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
92 ) |
5549
f2f42262adbd
hgweb.server: flush log files after every access
Patrick Mezard <pmezard@gmail.com>
parents:
5150
diff
changeset
|
93 fp.flush() |
f2f42262adbd
hgweb.server: flush log files after every access
Patrick Mezard <pmezard@gmail.com>
parents:
5150
diff
changeset
|
94 |
2355
eb08fb4d41e1
Splitting up hgweb so it's easier to change.
Eric Hopper <hopper@omnifarious.org>
parents:
2328
diff
changeset
|
95 def log_error(self, format, *args): |
5549
f2f42262adbd
hgweb.server: flush log files after every access
Patrick Mezard <pmezard@gmail.com>
parents:
5150
diff
changeset
|
96 self._log_any(self.server.errorlog, format, *args) |
131 | 97 |
2355
eb08fb4d41e1
Splitting up hgweb so it's easier to change.
Eric Hopper <hopper@omnifarious.org>
parents:
2328
diff
changeset
|
98 def log_message(self, format, *args): |
5549
f2f42262adbd
hgweb.server: flush log files after every access
Patrick Mezard <pmezard@gmail.com>
parents:
5150
diff
changeset
|
99 self._log_any(self.server.accesslog, format, *args) |
538 | 100 |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
101 def log_request(self, code='-', size='-'): |
19877
52ed85d9ac26
hgweb: log headers only if headers were successfully parsed
David Soria Parra <dsp@experimentalworks.net>
parents:
18380
diff
changeset
|
102 xheaders = [] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
103 if util.safehasattr(self, b'headers'): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
104 xheaders = [ |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
105 h for h in self.headers.items() if h[0].startswith('x-') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
106 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
107 self.log_message( |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
108 '"%s" %s %s%s', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
109 self.requestline, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
110 str(code), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
111 str(size), |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
112 ''.join([' %s:%s' % h for h in sorted(xheaders)]), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
113 ) |
14093
ce99d887585f
httprepo: long arguments support (issue2126)
Steven Brown <StevenGBrown@gmail.com>
parents:
13570
diff
changeset
|
114 |
4860
f3802f9f1840
Add SSL support to hg serve, activated via --certificate option
Brendan Cully <brendan@kublai.com>
parents:
4635
diff
changeset
|
115 def do_write(self): |
f3802f9f1840
Add SSL support to hg serve, activated via --certificate option
Brendan Cully <brendan@kublai.com>
parents:
4635
diff
changeset
|
116 try: |
f3802f9f1840
Add SSL support to hg serve, activated via --certificate option
Brendan Cully <brendan@kublai.com>
parents:
4635
diff
changeset
|
117 self.do_hgweb() |
49304
48f1b314056b
py3: catch BrokenPipeError instead of checking errno == EPIPE
Manuel Jacob <me@manueljacob.de>
parents:
49283
diff
changeset
|
118 except BrokenPipeError: |
48f1b314056b
py3: catch BrokenPipeError instead of checking errno == EPIPE
Manuel Jacob <me@manueljacob.de>
parents:
49283
diff
changeset
|
119 pass |
4860
f3802f9f1840
Add SSL support to hg serve, activated via --certificate option
Brendan Cully <brendan@kublai.com>
parents:
4635
diff
changeset
|
120 |
2355
eb08fb4d41e1
Splitting up hgweb so it's easier to change.
Eric Hopper <hopper@omnifarious.org>
parents:
2328
diff
changeset
|
121 def do_POST(self): |
eb08fb4d41e1
Splitting up hgweb so it's easier to change.
Eric Hopper <hopper@omnifarious.org>
parents:
2328
diff
changeset
|
122 try: |
4860
f3802f9f1840
Add SSL support to hg serve, activated via --certificate option
Brendan Cully <brendan@kublai.com>
parents:
4635
diff
changeset
|
123 self.do_write() |
41479
6bbb12cba5a8
server: skip logging of ECONNRESET
Augie Fackler <augie@google.com>
parents:
41462
diff
changeset
|
124 except Exception as e: |
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41430
diff
changeset
|
125 # I/O below could raise another exception. So log the original |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41430
diff
changeset
|
126 # exception first to ensure it is recorded. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
127 if not ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
128 isinstance(e, (OSError, socket.error)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
129 and e.errno == errno.ECONNRESET |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
130 ): |
43503
313e3a279828
cleanup: remove pointless r-prefixes on double-quoted strings
Augie Fackler <augie@google.com>
parents:
43457
diff
changeset
|
131 tb = "".join(traceback.format_exception(*sys.exc_info())) |
41479
6bbb12cba5a8
server: skip logging of ECONNRESET
Augie Fackler <augie@google.com>
parents:
41462
diff
changeset
|
132 # We need a native-string newline to poke in the log |
6bbb12cba5a8
server: skip logging of ECONNRESET
Augie Fackler <augie@google.com>
parents:
41462
diff
changeset
|
133 # message, because we won't get a newline when using an |
6bbb12cba5a8
server: skip logging of ECONNRESET
Augie Fackler <augie@google.com>
parents:
41462
diff
changeset
|
134 # r-string. This is the easy way out. |
6bbb12cba5a8
server: skip logging of ECONNRESET
Augie Fackler <augie@google.com>
parents:
41462
diff
changeset
|
135 newline = chr(10) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
136 self.log_error( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
137 r"Exception happened during processing " |
43503
313e3a279828
cleanup: remove pointless r-prefixes on double-quoted strings
Augie Fackler <augie@google.com>
parents:
43457
diff
changeset
|
138 "request '%s':%s%s", |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
139 self.path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
140 newline, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
141 tb, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
142 ) |
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
143 |
43503
313e3a279828
cleanup: remove pointless r-prefixes on double-quoted strings
Augie Fackler <augie@google.com>
parents:
43457
diff
changeset
|
144 self._start_response("500 Internal Server Error", []) |
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41430
diff
changeset
|
145 self._write(b"Internal Server Error") |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41430
diff
changeset
|
146 self._done() |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41430
diff
changeset
|
147 |
37147
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
37009
diff
changeset
|
148 def do_PUT(self): |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
37009
diff
changeset
|
149 self.do_POST() |
a2566597acb5
lfs: add basic routing for the server side wire protocol processing
Matt Harbison <matt_harbison@yahoo.com>
parents:
37009
diff
changeset
|
150 |
2355
eb08fb4d41e1
Splitting up hgweb so it's easier to change.
Eric Hopper <hopper@omnifarious.org>
parents:
2328
diff
changeset
|
151 def do_GET(self): |
eb08fb4d41e1
Splitting up hgweb so it's easier to change.
Eric Hopper <hopper@omnifarious.org>
parents:
2328
diff
changeset
|
152 self.do_POST() |
131 | 153 |
50090
a3c856e2ea2f
branching: merge with default
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49973
diff
changeset
|
154 def do_HEAD(self): |
a3c856e2ea2f
branching: merge with default
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49973
diff
changeset
|
155 self.do_POST() |
a3c856e2ea2f
branching: merge with default
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49973
diff
changeset
|
156 |
2355
eb08fb4d41e1
Splitting up hgweb so it's easier to change.
Eric Hopper <hopper@omnifarious.org>
parents:
2328
diff
changeset
|
157 def do_hgweb(self): |
34720
60e7da55e5e6
hgweb: set sent_headers attr as early as practical
Augie Fackler <augie@google.com>
parents:
34719
diff
changeset
|
158 self.sent_headers = False |
5835
bd34f0ac3cb0
adding "prefix" option to "hg serve" (command line and [web] section)
Michele Cella <michele.cella@gmail.com>
parents:
5690
diff
changeset
|
159 path, query = _splitURI(self.path) |
138 | 160 |
37156
7de7bd407251
server: ensure the incoming request falls under the prefix value
Matt Harbison <matt_harbison@yahoo.com>
parents:
34740
diff
changeset
|
161 # Ensure the slicing of path below is valid |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
162 if path != self.server.prefix and not path.startswith( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
163 self.server.prefix + b'/' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
164 ): |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
165 self._start_response(pycompat.strurl(common.statusmessage(404)), []) |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
166 if self.command == 'POST': |
41023
197f092b2cd9
server: always close http socket if responding with an error (issue6033)
Augie Fackler <raf@durin42.com>
parents:
39954
diff
changeset
|
167 # Paranoia: tell the client we're going to close the |
197f092b2cd9
server: always close http socket if responding with an error (issue6033)
Augie Fackler <raf@durin42.com>
parents:
39954
diff
changeset
|
168 # socket so they don't try and reuse a socket that |
197f092b2cd9
server: always close http socket if responding with an error (issue6033)
Augie Fackler <raf@durin42.com>
parents:
39954
diff
changeset
|
169 # might have a POST body waiting to confuse us. We do |
197f092b2cd9
server: always close http socket if responding with an error (issue6033)
Augie Fackler <raf@durin42.com>
parents:
39954
diff
changeset
|
170 # this by directly munging self.saved_headers because |
197f092b2cd9
server: always close http socket if responding with an error (issue6033)
Augie Fackler <raf@durin42.com>
parents:
39954
diff
changeset
|
171 # self._start_response ignores Connection headers. |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
172 self.saved_headers = [('Connection', 'Close')] |
38297
9f499d28efb4
hgweb: pass a sysstr to low-level _start_response method
Augie Fackler <augie@google.com>
parents:
37788
diff
changeset
|
173 self._write(b"Not Found") |
37156
7de7bd407251
server: ensure the incoming request falls under the prefix value
Matt Harbison <matt_harbison@yahoo.com>
parents:
34740
diff
changeset
|
174 self._done() |
7de7bd407251
server: ensure the incoming request falls under the prefix value
Matt Harbison <matt_harbison@yahoo.com>
parents:
34740
diff
changeset
|
175 return |
7de7bd407251
server: ensure the incoming request falls under the prefix value
Matt Harbison <matt_harbison@yahoo.com>
parents:
34740
diff
changeset
|
176 |
2355
eb08fb4d41e1
Splitting up hgweb so it's easier to change.
Eric Hopper <hopper@omnifarious.org>
parents:
2328
diff
changeset
|
177 env = {} |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
178 env['GATEWAY_INTERFACE'] = 'CGI/1.1' |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
179 env['REQUEST_METHOD'] = self.command |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
180 env['SERVER_NAME'] = self.server.server_name |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
181 env['SERVER_PORT'] = str(self.server.server_port) |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
182 env['REQUEST_URI'] = self.path |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
183 env['SCRIPT_NAME'] = pycompat.sysstr(self.server.prefix) |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
184 env['PATH_INFO'] = pycompat.sysstr(path[len(self.server.prefix) :]) |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
185 env['REMOTE_HOST'] = self.client_address[0] |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
186 env['REMOTE_ADDR'] = self.client_address[0] |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
187 env['QUERY_STRING'] = query or '' |
1579
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
188 |
48906
e453c69821f8
hgweb: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
189 if self.headers.get_content_type() is None: |
e453c69821f8
hgweb: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
190 env['CONTENT_TYPE'] = self.headers.get_default_type() |
34719
6e1b05692b2c
hgweb: detect Python 3-era libraries and use modern attribute names
Augie Fackler <augie@google.com>
parents:
34718
diff
changeset
|
191 else: |
48906
e453c69821f8
hgweb: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
192 env['CONTENT_TYPE'] = self.headers.get_content_type() |
e453c69821f8
hgweb: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
193 length = self.headers.get('content-length') |
2355
eb08fb4d41e1
Splitting up hgweb so it's easier to change.
Eric Hopper <hopper@omnifarious.org>
parents:
2328
diff
changeset
|
194 if length: |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
195 env['CONTENT_LENGTH'] = length |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
196 for header in [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
197 h |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
198 for h in self.headers.keys() |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
199 if h.lower() not in ('content-type', 'content-length') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
200 ]: |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
201 hkey = 'HTTP_' + header.replace('-', '_').upper() |
34512
482d6f6dba91
hgweb: when constructing or adding to a wsgi environ dict, use native strs
Augie Fackler <augie@google.com>
parents:
34376
diff
changeset
|
202 hval = self.headers.get(header) |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
203 hval = hval.replace('\n', '').strip() |
2505
01b856927970
Fix server to set up a more WSGI compliant environment.
Eric Hopper <hopper@omnifarious.org>
parents:
2434
diff
changeset
|
204 if hval: |
01b856927970
Fix server to set up a more WSGI compliant environment.
Eric Hopper <hopper@omnifarious.org>
parents:
2434
diff
changeset
|
205 env[hkey] = hval |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
206 env['SERVER_PROTOCOL'] = self.request_version |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
207 env['wsgi.version'] = (1, 0) |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
208 env['wsgi.url_scheme'] = pycompat.sysstr(self.url_scheme) |
49973
68cf519429ef
hgweb: unbyteify the 100-continue check
Matt Harbison <matt_harbison@yahoo.com>
parents:
49304
diff
changeset
|
209 if env.get('HTTP_EXPECT', '').lower() == '100-continue': |
13570
617a87cb7eb2
hgweb: add support for 100-continue as recommended by PEP 333.
Augie Fackler <durin42@gmail.com>
parents:
13443
diff
changeset
|
210 self.rfile = common.continuereader(self.rfile, self.wfile.write) |
617a87cb7eb2
hgweb: add support for 100-continue as recommended by PEP 333.
Augie Fackler <durin42@gmail.com>
parents:
13443
diff
changeset
|
211 |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
212 env['wsgi.input'] = self.rfile |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
213 env['wsgi.errors'] = _error_logger(self) |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
214 env['wsgi.multithread'] = isinstance( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
215 self.server, socketserver.ThreadingMixIn |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
216 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
217 if util.safehasattr(socketserver, b'ForkingMixIn'): |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
218 env['wsgi.multiprocess'] = isinstance( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
219 self.server, socketserver.ForkingMixIn |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
220 ) |
39834
d1e0b905c59d
py3: conditionalize access to socketserver.ForkingMixIn
Matt Harbison <matt_harbison@yahoo.com>
parents:
39827
diff
changeset
|
221 else: |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
222 env['wsgi.multiprocess'] = False |
39834
d1e0b905c59d
py3: conditionalize access to socketserver.ForkingMixIn
Matt Harbison <matt_harbison@yahoo.com>
parents:
39827
diff
changeset
|
223 |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
224 env['wsgi.run_once'] = 0 |
601 | 225 |
36803
8e1556ac01bb
hgweb: validate WSGI environment dict
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36802
diff
changeset
|
226 wsgiref.validate.check_environ(env) |
8e1556ac01bb
hgweb: validate WSGI environment dict
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36802
diff
changeset
|
227 |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
228 self.saved_status = None |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
229 self.saved_headers = [] |
2508
ab460a3f0e3a
Put support for persistent connections back in.
Eric Hopper <hopper@omnifarious.org>
parents:
2507
diff
changeset
|
230 self.length = None |
18354
cf5c76017e11
serve: use chunked encoding in hgweb responses
Mads Kiilerich <mads@kiilerich.com>
parents:
18353
diff
changeset
|
231 self._chunked = None |
6784
18c429ea3a0e
hgweb: all protocol functions have become generators
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6403
diff
changeset
|
232 for chunk in self.server.application(env, self._start_response): |
18c429ea3a0e
hgweb: all protocol functions have become generators
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6403
diff
changeset
|
233 self._write(chunk) |
18349
c007e5c54b16
serve: send response headers even if response has no body
Mads Kiilerich <mads@kiilerich.com>
parents:
17427
diff
changeset
|
234 if not self.sent_headers: |
c007e5c54b16
serve: send response headers even if response has no body
Mads Kiilerich <mads@kiilerich.com>
parents:
17427
diff
changeset
|
235 self.send_headers() |
18354
cf5c76017e11
serve: use chunked encoding in hgweb responses
Mads Kiilerich <mads@kiilerich.com>
parents:
18353
diff
changeset
|
236 self._done() |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
237 |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
238 def send_headers(self): |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
239 if not self.saved_status: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
240 raise AssertionError( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43089
diff
changeset
|
241 b"Sending headers before start_response() called" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
242 ) |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
243 saved_status = self.saved_status.split(None, 1) |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
244 saved_status[0] = int(saved_status[0]) |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
245 self.send_response(*saved_status) |
18354
cf5c76017e11
serve: use chunked encoding in hgweb responses
Mads Kiilerich <mads@kiilerich.com>
parents:
18353
diff
changeset
|
246 self.length = None |
cf5c76017e11
serve: use chunked encoding in hgweb responses
Mads Kiilerich <mads@kiilerich.com>
parents:
18353
diff
changeset
|
247 self._chunked = False |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
248 for h in self.saved_headers: |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
249 self.send_header(*h) |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
250 if h[0].lower() == 'content-length': |
2508
ab460a3f0e3a
Put support for persistent connections back in.
Eric Hopper <hopper@omnifarious.org>
parents:
2507
diff
changeset
|
251 self.length = int(h[1]) |
50090
a3c856e2ea2f
branching: merge with default
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49973
diff
changeset
|
252 if ( |
a3c856e2ea2f
branching: merge with default
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49973
diff
changeset
|
253 self.length is None |
a3c856e2ea2f
branching: merge with default
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49973
diff
changeset
|
254 and saved_status[0] != common.HTTP_NOT_MODIFIED |
a3c856e2ea2f
branching: merge with default
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49973
diff
changeset
|
255 and self.command != 'HEAD' |
a3c856e2ea2f
branching: merge with default
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49973
diff
changeset
|
256 ): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
257 self._chunked = ( |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
258 not self.close_connection and self.request_version == 'HTTP/1.1' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
259 ) |
18354
cf5c76017e11
serve: use chunked encoding in hgweb responses
Mads Kiilerich <mads@kiilerich.com>
parents:
18353
diff
changeset
|
260 if self._chunked: |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
261 self.send_header('Transfer-Encoding', 'chunked') |
18354
cf5c76017e11
serve: use chunked encoding in hgweb responses
Mads Kiilerich <mads@kiilerich.com>
parents:
18353
diff
changeset
|
262 else: |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
263 self.send_header('Connection', 'close') |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
264 self.end_headers() |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
265 self.sent_headers = True |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
266 |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
267 def _start_response(self, http_status, headers, exc_info=None): |
38298
af0e88e64ede
hgweb: insist http_status value is a sysstr
Augie Fackler <augie@google.com>
parents:
38297
diff
changeset
|
268 assert isinstance(http_status, str) |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
269 code, msg = http_status.split(None, 1) |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
270 code = int(code) |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
271 self.saved_status = http_status |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
272 bad_headers = ('connection', 'transfer-encoding') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
273 self.saved_headers = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
274 h for h in headers if h[0].lower() not in bad_headers |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
275 ] |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
276 return self._write |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
277 |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
278 def _write(self, data): |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
279 if not self.saved_status: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
280 raise AssertionError(b"data written before start_response() called") |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
281 elif not self.sent_headers: |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
282 self.send_headers() |
2508
ab460a3f0e3a
Put support for persistent connections back in.
Eric Hopper <hopper@omnifarious.org>
parents:
2507
diff
changeset
|
283 if self.length is not None: |
ab460a3f0e3a
Put support for persistent connections back in.
Eric Hopper <hopper@omnifarious.org>
parents:
2507
diff
changeset
|
284 if len(data) > self.length: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
285 raise AssertionError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
286 b"Content-length header sent, but more " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
287 b"bytes than specified are being written." |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
288 ) |
2508
ab460a3f0e3a
Put support for persistent connections back in.
Eric Hopper <hopper@omnifarious.org>
parents:
2507
diff
changeset
|
289 self.length = self.length - len(data) |
18354
cf5c76017e11
serve: use chunked encoding in hgweb responses
Mads Kiilerich <mads@kiilerich.com>
parents:
18353
diff
changeset
|
290 elif self._chunked and data: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
291 data = b'%x\r\n%s\r\n' % (len(data), data) |
2506
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
292 self.wfile.write(data) |
d0db3462d568
This patch make several WSGI related alterations.
Eric Hopper <hopper@omnifarious.org>
parents:
2505
diff
changeset
|
293 self.wfile.flush() |
136 | 294 |
18354
cf5c76017e11
serve: use chunked encoding in hgweb responses
Mads Kiilerich <mads@kiilerich.com>
parents:
18353
diff
changeset
|
295 def _done(self): |
cf5c76017e11
serve: use chunked encoding in hgweb responses
Mads Kiilerich <mads@kiilerich.com>
parents:
18353
diff
changeset
|
296 if self._chunked: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
297 self.wfile.write(b'0\r\n\r\n') |
18354
cf5c76017e11
serve: use chunked encoding in hgweb responses
Mads Kiilerich <mads@kiilerich.com>
parents:
18353
diff
changeset
|
298 self.wfile.flush() |
cf5c76017e11
serve: use chunked encoding in hgweb responses
Mads Kiilerich <mads@kiilerich.com>
parents:
18353
diff
changeset
|
299 |
37009
5890e5872f36
hgweb: allow defining Server response header for HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36803
diff
changeset
|
300 def version_string(self): |
5890e5872f36
hgweb: allow defining Server response header for HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36803
diff
changeset
|
301 if self.server.serverheader: |
38594
b263133eeb5a
py3: convert server-string to unicode to make http library happy
Yuya Nishihara <yuya@tcha.org>
parents:
38298
diff
changeset
|
302 return encoding.strfromlocal(self.server.serverheader) |
37009
5890e5872f36
hgweb: allow defining Server response header for HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36803
diff
changeset
|
303 return httpservermod.basehttprequesthandler.version_string(self) |
5890e5872f36
hgweb: allow defining Server response header for HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36803
diff
changeset
|
304 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
305 |
12784
763be3cd084a
hgweb: use Pythons ssl module for HTTPS serve when using Python 2.6 or later
Mads Kiilerich <mads@kiilerich.com>
parents:
12783
diff
changeset
|
306 class _httprequesthandlerssl(_httprequesthandler): |
26202
04af43009c8b
hgweb.server: fix _httprequesthandlerssl help text
timeless@mozdev.org
parents:
25660
diff
changeset
|
307 """HTTPS handler based on Python's ssl module""" |
12784
763be3cd084a
hgweb: use Pythons ssl module for HTTPS serve when using Python 2.6 or later
Mads Kiilerich <mads@kiilerich.com>
parents:
12783
diff
changeset
|
308 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
309 url_scheme = b'https' |
12784
763be3cd084a
hgweb: use Pythons ssl module for HTTPS serve when using Python 2.6 or later
Mads Kiilerich <mads@kiilerich.com>
parents:
12783
diff
changeset
|
310 |
763be3cd084a
hgweb: use Pythons ssl module for HTTPS serve when using Python 2.6 or later
Mads Kiilerich <mads@kiilerich.com>
parents:
12783
diff
changeset
|
311 @staticmethod |
29553
cd3e58862cab
hgweb: pass ui into preparehttpserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29433
diff
changeset
|
312 def preparehttpserver(httpserver, ui): |
12784
763be3cd084a
hgweb: use Pythons ssl module for HTTPS serve when using Python 2.6 or later
Mads Kiilerich <mads@kiilerich.com>
parents:
12783
diff
changeset
|
313 try: |
29555
121d11814c62
hgweb: use sslutil.wrapserversocket()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29553
diff
changeset
|
314 from .. import sslutil |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
315 |
44877
86a7b7abf28e
hgweb: avoid using `sslutil.modernssl`
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
316 sslutil.wrapserversocket |
12784
763be3cd084a
hgweb: use Pythons ssl module for HTTPS serve when using Python 2.6 or later
Mads Kiilerich <mads@kiilerich.com>
parents:
12783
diff
changeset
|
317 except ImportError: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
318 raise error.Abort(_(b"SSL support is unavailable")) |
29553
cd3e58862cab
hgweb: pass ui into preparehttpserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29433
diff
changeset
|
319 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
320 certfile = ui.config(b'web', b'certificate') |
29555
121d11814c62
hgweb: use sslutil.wrapserversocket()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29553
diff
changeset
|
321 |
121d11814c62
hgweb: use sslutil.wrapserversocket()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29553
diff
changeset
|
322 # These config options are currently only meant for testing. Use |
121d11814c62
hgweb: use sslutil.wrapserversocket()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29553
diff
changeset
|
323 # at your own risk. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
324 cafile = ui.config(b'devel', b'servercafile') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
325 reqcert = ui.configbool(b'devel', b'serverrequirecert') |
29555
121d11814c62
hgweb: use sslutil.wrapserversocket()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29553
diff
changeset
|
326 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
327 httpserver.socket = sslutil.wrapserversocket( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
328 httpserver.socket, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
329 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
330 certfile=certfile, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
331 cafile=cafile, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
332 requireclientcert=reqcert, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
333 ) |
12784
763be3cd084a
hgweb: use Pythons ssl module for HTTPS serve when using Python 2.6 or later
Mads Kiilerich <mads@kiilerich.com>
parents:
12783
diff
changeset
|
334 |
763be3cd084a
hgweb: use Pythons ssl module for HTTPS serve when using Python 2.6 or later
Mads Kiilerich <mads@kiilerich.com>
parents:
12783
diff
changeset
|
335 def setup(self): |
763be3cd084a
hgweb: use Pythons ssl module for HTTPS serve when using Python 2.6 or later
Mads Kiilerich <mads@kiilerich.com>
parents:
12783
diff
changeset
|
336 self.connection = self.request |
43503
313e3a279828
cleanup: remove pointless r-prefixes on double-quoted strings
Augie Fackler <augie@google.com>
parents:
43457
diff
changeset
|
337 self.rfile = self.request.makefile("rb", self.rbufsize) |
313e3a279828
cleanup: remove pointless r-prefixes on double-quoted strings
Augie Fackler <augie@google.com>
parents:
43457
diff
changeset
|
338 self.wfile = self.request.makefile("wb", self.wbufsize) |
12784
763be3cd084a
hgweb: use Pythons ssl module for HTTPS serve when using Python 2.6 or later
Mads Kiilerich <mads@kiilerich.com>
parents:
12783
diff
changeset
|
339 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
340 |
10639
a6808629f450
server: externalize and streamline mixin setup
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10638
diff
changeset
|
341 try: |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
26848
diff
changeset
|
342 import threading |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
343 |
47194
acd84c434896
hgweb: Fix deprecation warning in Python 3.10 (issue6520)
Karthikeyan Singaravelan <tir.karthi@gmail.com>
parents:
46907
diff
changeset
|
344 threading.active_count() # silence pyflakes and bypass demandimport |
29433
33770d2b6cf9
py3: conditionalize SocketServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28883
diff
changeset
|
345 _mixin = socketserver.ThreadingMixIn |
10639
a6808629f450
server: externalize and streamline mixin setup
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10638
diff
changeset
|
346 except ImportError: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
347 if util.safehasattr(os, b"fork"): |
29433
33770d2b6cf9
py3: conditionalize SocketServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28883
diff
changeset
|
348 _mixin = socketserver.ForkingMixIn |
10639
a6808629f450
server: externalize and streamline mixin setup
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10638
diff
changeset
|
349 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
350 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48906
diff
changeset
|
351 class _mixin: |
10639
a6808629f450
server: externalize and streamline mixin setup
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10638
diff
changeset
|
352 pass |
a6808629f450
server: externalize and streamline mixin setup
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10638
diff
changeset
|
353 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
354 |
10643
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
355 def openlog(opt, default): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
356 if opt and opt != b'-': |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
357 return open(opt, b'ab') |
10643
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
358 return default |
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
359 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
360 |
30082
ebc03e64548a
hgweb: fix the MRO in Python 3
Martijn Pieters <mjpieters@fb.com>
parents:
29566
diff
changeset
|
361 class MercurialHTTPServer(_mixin, httpservermod.httpserver, object): |
10643
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
362 |
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
363 # SO_REUSEADDR has broken semantics on windows |
34645 | 364 if pycompat.iswindows: |
10643
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
365 allow_reuse_address = 0 |
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
366 |
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
367 def __init__(self, ui, app, addr, handler, **kwargs): |
29566
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29555
diff
changeset
|
368 httpservermod.httpserver.__init__(self, addr, handler, **kwargs) |
10643
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
369 self.daemon_threads = True |
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
370 self.application = app |
2124
27fd8b7a6c51
Cleaned trailing whitespace in hgweb.py, removed command line shortcut for webdir-conf.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
2123
diff
changeset
|
371 |
29553
cd3e58862cab
hgweb: pass ui into preparehttpserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29433
diff
changeset
|
372 handler.preparehttpserver(self, ui) |
10643
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
373 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
374 prefix = ui.config(b'web', b'prefix') |
10643
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
375 if prefix: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
376 prefix = b'/' + prefix.strip(b'/') |
10643
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
377 self.prefix = prefix |
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
378 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
379 alog = openlog(ui.config(b'web', b'accesslog'), ui.fout) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
380 elog = openlog(ui.config(b'web', b'errorlog'), ui.ferr) |
10643
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
381 self.accesslog = alog |
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
382 self.errorlog = elog |
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
383 |
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
384 self.addr, self.port = self.socket.getsockname()[0:2] |
45034
b1a1702262c9
py3: fix crash when server address is 0.0.0.0 (issue6362)
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
385 self.fqaddr = self.server_name |
10643
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
386 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
387 self.serverheader = ui.config(b'web', b'server-header') |
37009
5890e5872f36
hgweb: allow defining Server response header for HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36803
diff
changeset
|
388 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
389 |
10643
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
390 class IPv6HTTPServer(MercurialHTTPServer): |
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
391 address_family = getattr(socket, 'AF_INET6', None) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
392 |
10643
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
393 def __init__(self, *args, **kwargs): |
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
394 if self.address_family is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
395 raise error.RepoError(_(b'IPv6 is not available on this system')) |
10643
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
396 super(IPv6HTTPServer, self).__init__(*args, **kwargs) |
1874697a8863
server: unnest server classes into module namespace
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10642
diff
changeset
|
397 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
398 |
10644
63948e7d37f7
server: initialize wsgi app in command, then wrap server around it
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10643
diff
changeset
|
399 def create_server(ui, app): |
938 | 400 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
401 if ui.config(b'web', b'certificate'): |
26848
d962e955da08
hgweb.server: drop support for Python 2.4
Siddharth Agarwal <sid0@fb.com>
parents:
26587
diff
changeset
|
402 handler = _httprequesthandlerssl |
4860
f3802f9f1840
Add SSL support to hg serve, activated via --certificate option
Brendan Cully <brendan@kublai.com>
parents:
4635
diff
changeset
|
403 else: |
12783
191d0fd5c2fd
hgweb: refactor all pyOpenSSL references into one class
Mads Kiilerich <mads@kiilerich.com>
parents:
12740
diff
changeset
|
404 handler = _httprequesthandler |
4860
f3802f9f1840
Add SSL support to hg serve, activated via --certificate option
Brendan Cully <brendan@kublai.com>
parents:
4635
diff
changeset
|
405 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
406 if ui.configbool(b'web', b'ipv6'): |
10641
dedf88fe945a
server: abstract setup of ipv6 vs. normal server
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10640
diff
changeset
|
407 cls = IPv6HTTPServer |
dedf88fe945a
server: abstract setup of ipv6 vs. normal server
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10640
diff
changeset
|
408 else: |
dedf88fe945a
server: abstract setup of ipv6 vs. normal server
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10640
diff
changeset
|
409 cls = MercurialHTTPServer |
dedf88fe945a
server: abstract setup of ipv6 vs. normal server
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10640
diff
changeset
|
410 |
8224
1075f5c1b3fa
hgweb: pre-init mimetypes module (fixes ugly bug in python-2.6.2 mimetypes)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7928
diff
changeset
|
411 # ugly hack due to python issue5853 (for threaded use) |
49283
44b26349127b
hgweb: remove dead code handling UnicodeDecodeError
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
412 import mimetypes |
20357
6863d42eb59a
hgweb: hack around mimetypes encoding thinko (issue4160)
Matt Mackall <mpm@selenic.com>
parents:
19877
diff
changeset
|
413 |
49283
44b26349127b
hgweb: remove dead code handling UnicodeDecodeError
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
414 mimetypes.init() |
8224
1075f5c1b3fa
hgweb: pre-init mimetypes module (fixes ugly bug in python-2.6.2 mimetypes)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7928
diff
changeset
|
415 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
416 address = ui.config(b'web', b'address') |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46819
diff
changeset
|
417 port = urlutil.getport(ui.config(b'web', b'port')) |
3628
dc3504af7722
hgweb: internalize some socket details
Matt Mackall <mpm@selenic.com>
parents:
3263
diff
changeset
|
418 try: |
10644
63948e7d37f7
server: initialize wsgi app in command, then wrap server around it
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10643
diff
changeset
|
419 return cls(ui, app, (address, port), handler) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23409
diff
changeset
|
420 except socket.error as inst: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
421 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
422 _(b"cannot start server at '%s:%d': %s") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
423 % (address, port, encoding.strtolocal(inst.args[1])) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43069
diff
changeset
|
424 ) |