D2830: hgweb: remove dead wsgirequest code
This revision was automatically updated to reflect the committed changes. Closed by commit rHGcd6ae9ab7bd8: hgweb: remove dead wsgirequest code (authored by indygreg, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2830?vs=6896=6961 REVISION DETAIL https://phab.mercurial-scm.org/D2830 AFFECTED FILES mercurial/hgweb/hgwebdir_mod.py mercurial/hgweb/request.py CHANGE DETAILS diff --git a/mercurial/hgweb/request.py b/mercurial/hgweb/request.py --- a/mercurial/hgweb/request.py +++ b/mercurial/hgweb/request.py @@ -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: -
D2830: hgweb: remove dead wsgirequest code
indygreg created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY All responses now go through our modern response type. All code related to response handling can be deleted. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2830 AFFECTED FILES mercurial/hgweb/hgwebdir_mod.py mercurial/hgweb/request.py CHANGE DETAILS diff --git a/mercurial/hgweb/request.py b/mercurial/hgweb/request.py --- a/mercurial/hgweb/request.py +++ b/mercurial/hgweb/request.py @@ -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) -