Show More
@@ -62,6 +62,16 b" def makebreadcrumb(url, prefix=''):" | |||||
62 |
|
62 | |||
63 |
|
63 | |||
64 | class hgweb(object): |
|
64 | class hgweb(object): | |
|
65 | """HTTP server for individual repositories. | |||
|
66 | ||||
|
67 | Instances of this class serve HTTP responses for a particular | |||
|
68 | repository. | |||
|
69 | ||||
|
70 | Instances are typically used as WSGI applications. | |||
|
71 | ||||
|
72 | Some servers are multi-threaded. On these servers, there may | |||
|
73 | be multiple active threads inside __call__. | |||
|
74 | """ | |||
65 | def __init__(self, repo, name=None, baseui=None): |
|
75 | def __init__(self, repo, name=None, baseui=None): | |
66 | if isinstance(repo, str): |
|
76 | if isinstance(repo, str): | |
67 | if baseui: |
|
77 | if baseui: | |
@@ -157,6 +167,11 b' class hgweb(object):' | |||||
157 | self.repo.ui.environ = request.env |
|
167 | self.repo.ui.environ = request.env | |
158 |
|
168 | |||
159 | def run(self): |
|
169 | def run(self): | |
|
170 | """Start a server from CGI environment. | |||
|
171 | ||||
|
172 | Modern servers should be using WSGI and should avoid this | |||
|
173 | method, if possible. | |||
|
174 | """ | |||
160 | if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."): |
|
175 | if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."): | |
161 | raise RuntimeError("This function is only intended to be " |
|
176 | raise RuntimeError("This function is only intended to be " | |
162 | "called while running as a CGI script.") |
|
177 | "called while running as a CGI script.") | |
@@ -164,11 +179,19 b' class hgweb(object):' | |||||
164 | wsgicgi.launch(self) |
|
179 | wsgicgi.launch(self) | |
165 |
|
180 | |||
166 | def __call__(self, env, respond): |
|
181 | def __call__(self, env, respond): | |
|
182 | """Run the WSGI application. | |||
|
183 | ||||
|
184 | This may be called by multiple threads. | |||
|
185 | """ | |||
167 | req = wsgirequest(env, respond) |
|
186 | req = wsgirequest(env, respond) | |
168 | return self.run_wsgi(req) |
|
187 | return self.run_wsgi(req) | |
169 |
|
188 | |||
170 | def run_wsgi(self, req): |
|
189 | def run_wsgi(self, req): | |
|
190 | """Internal method to run the WSGI application. | |||
171 |
|
|
191 | ||
|
192 | This is typically only called by Mercurial. External consumers | |||
|
193 | should be using instances of this class as the WSGI application. | |||
|
194 | """ | |||
172 | self.refresh(req) |
|
195 | self.refresh(req) | |
173 |
|
196 | |||
174 | # work with CGI variables to create coherent structure |
|
197 | # work with CGI variables to create coherent structure |
@@ -79,6 +79,13 b' def geturlcgivars(baseurl, port):' | |||||
79 | return name, str(port), path |
|
79 | return name, str(port), path | |
80 |
|
80 | |||
81 | class hgwebdir(object): |
|
81 | class hgwebdir(object): | |
|
82 | """HTTP server for multiple repositories. | |||
|
83 | ||||
|
84 | Given a configuration, different repositories will be served depending | |||
|
85 | on the request path. | |||
|
86 | ||||
|
87 | Instances are typically used as WSGI applications. | |||
|
88 | """ | |||
82 | def __init__(self, conf, baseui=None): |
|
89 | def __init__(self, conf, baseui=None): | |
83 | self.conf = conf |
|
90 | self.conf = conf | |
84 | self.baseui = baseui |
|
91 | self.baseui = baseui |
@@ -40,6 +40,12 b' def normalize(form):' | |||||
40 | return form |
|
40 | return form | |
41 |
|
41 | |||
42 | class wsgirequest(object): |
|
42 | class wsgirequest(object): | |
|
43 | """Higher-level API for a WSGI request. | |||
|
44 | ||||
|
45 | WSGI applications are invoked with 2 arguments. They are used to | |||
|
46 | instantiate instances of this class, which provides higher-level APIs | |||
|
47 | for obtaining request parameters, writing HTTP output, etc. | |||
|
48 | """ | |||
43 | def __init__(self, wsgienv, start_response): |
|
49 | def __init__(self, wsgienv, start_response): | |
44 | version = wsgienv['wsgi.version'] |
|
50 | version = wsgienv['wsgi.version'] | |
45 | if (version < (1, 0)) or (version >= (2, 0)): |
|
51 | if (version < (1, 0)) or (version >= (2, 0)): |
General Comments 0
You need to be logged in to leave comments.
Login now