Mercurial > hg-stable
changeset 36914:cd6ae9ab7bd8
hgweb: remove dead wsgirequest code
All responses now go through our modern response type. All code related
to response handling can be deleted.
Differential Revision: https://phab.mercurial-scm.org/D2830
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 11 Mar 2018 15:55:38 -0700 |
parents | c1de7efca574 |
children | 84110a1d0f7d |
files | mercurial/hgweb/hgwebdir_mod.py mercurial/hgweb/request.py |
diffstat | 2 files changed, 0 insertions(+), 102 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/hgwebdir_mod.py Sun Mar 11 15:40:58 2018 -0700 +++ b/mercurial/hgweb/hgwebdir_mod.py Sun Mar 11 15:55:38 2018 -0700 @@ -367,7 +367,6 @@ csp, nonce = cspvalues(self.ui) if csp: res.headers['Content-Security-Policy'] = csp - wsgireq.headers.append(('Content-Security-Policy', csp)) virtual = req.dispatchpath.strip('/') tmpl = self.templater(req, nonce)
--- a/mercurial/hgweb/request.py Sun Mar 11 15:40:58 2018 -0700 +++ b/mercurial/hgweb/request.py Sun Mar 11 15:55:38 2018 -0700 @@ -8,16 +8,9 @@ from __future__ import absolute_import -import errno -import socket import wsgiref.headers as wsgiheaders #import wsgiref.validate -from .common import ( - ErrorResponse, - statusmessage, -) - from ..thirdparty import ( attr, ) @@ -609,100 +602,6 @@ self.env = wsgienv self.req = parserequestfromenv(wsgienv, inp, altbaseurl=altbaseurl) self.res = wsgiresponse(self.req, start_response) - self._start_response = start_response - self.server_write = None - self.headers = [] - - def respond(self, status, type, filename=None, body=None): - if not isinstance(type, str): - type = pycompat.sysstr(type) - if self._start_response is not None: - self.headers.append((r'Content-Type', type)) - if filename: - filename = (filename.rpartition('/')[-1] - .replace('\\', '\\\\').replace('"', '\\"')) - self.headers.append(('Content-Disposition', - 'inline; filename="%s"' % filename)) - if body is not None: - self.headers.append((r'Content-Length', str(len(body)))) - - for k, v in self.headers: - if not isinstance(v, str): - raise TypeError('header value must be string: %r' % (v,)) - - if isinstance(status, ErrorResponse): - self.headers.extend(status.headers) - status = statusmessage(status.code, pycompat.bytestr(status)) - elif status == 200: - status = '200 Script output follows' - elif isinstance(status, int): - status = statusmessage(status) - - # Various HTTP clients (notably httplib) won't read the HTTP - # response until the HTTP request has been sent in full. If servers - # (us) send a response before the HTTP request has been fully sent, - # the connection may deadlock because neither end is reading. - # - # We work around this by "draining" the request data before - # sending any response in some conditions. - drain = False - close = False - - # If the client sent Expect: 100-continue, we assume it is smart - # enough to deal with the server sending a response before reading - # the request. (httplib doesn't do this.) - if self.env.get(r'HTTP_EXPECT', r'').lower() == r'100-continue': - pass - # Only tend to request methods that have bodies. Strictly speaking, - # we should sniff for a body. But this is fine for our existing - # WSGI applications. - elif self.env[r'REQUEST_METHOD'] not in (r'POST', r'PUT'): - pass - else: - # If we don't know how much data to read, there's no guarantee - # that we can drain the request responsibly. The WSGI - # specification only says that servers *should* ensure the - # input stream doesn't overrun the actual request. So there's - # no guarantee that reading until EOF won't corrupt the stream - # state. - if not isinstance(self.req.bodyfh, util.cappedreader): - close = True - else: - # We /could/ only drain certain HTTP response codes. But 200 - # and non-200 wire protocol responses both require draining. - # Since we have a capped reader in place for all situations - # where we drain, it is safe to read from that stream. We'll - # either do a drain or no-op if we're already at EOF. - drain = True - - if close: - self.headers.append((r'Connection', r'Close')) - - if drain: - assert isinstance(self.req.bodyfh, util.cappedreader) - while True: - chunk = self.req.bodyfh.read(32768) - if not chunk: - break - - self.server_write = self._start_response( - pycompat.sysstr(status), self.headers) - self._start_response = None - self.headers = [] - if body is not None: - self.write(body) - self.server_write = None - - def write(self, thing): - if thing: - try: - self.server_write(thing) - except socket.error as inst: - if inst[0] != errno.ECONNRESET: - raise - - def flush(self): - return None def wsgiapplication(app_maker): '''For compatibility with old CGI scripts. A plain hgweb() or hgwebdir()