Skip to content

Commit

Permalink
Extract FakeResponse.server_protocol attribute
Browse files Browse the repository at this point in the history
zope.app.testing.functional.http() used to respond with "HTTP/1.1 ...",
zope.app.wsgi.testlayer.http() hardcodes the server protocol as
"HTTP/1.0 ...".

This is annoying when I'm trying to port old large test suites.  Let's
at least make this easier to customize by subclassing and overriding a
single attribute, without having to rewrite the entire method.
  • Loading branch information
mgedmin committed Jun 6, 2019
1 parent c36e30f commit f2cfd0d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/zope/app/wsgi/testlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class FakeResponse(object):
"""

# XXX: zope.app.testing.functional used to respond with HTTP/1.1
server_protocol = b'HTTP/1.0'

def __init__(self, response):
self.response = response

Expand All @@ -173,7 +176,7 @@ def getBody(self):
def getOutput(self):
status = self.response.status
status = status.encode('latin1') if not isinstance(status, bytes) else status
parts = [b'HTTP/1.0 ' + status]
parts = [self.server_protocol + b' ' + status]

headers = [(k.encode('latin1') if not isinstance(k, bytes) else k,
v.encode('latin1') if not isinstance(v, bytes) else v)
Expand Down Expand Up @@ -241,6 +244,7 @@ def request(self, host, handler, request_body, verbose=0):
dict(extra_headers)["Authorization"],)

request += "\n" + request_body
# XXX: http() needs to be passed a wsgi app! where do we get a wsgi app?
response = http(request, handle_errors=self.handleErrors)

errcode = response.getStatus()
Expand Down

0 comments on commit f2cfd0d

Please sign in to comment.