Content-Length enforcement fixups
Change-Id: Ice8144700cf447ecf5c6175dc64aa7662013fba5 Related-Change: I74d8c13eba2a4917b5a116875b51a781b33a7abf
This commit is contained in:
parent
4a0afa9fea
commit
8bfb97a3a8
@ -69,7 +69,6 @@ class CatchErrorsContext(WSGIContext):
|
||||
|
||||
trans_id = generate_trans_id(trans_id_suffix)
|
||||
env['swift.trans_id'] = trans_id
|
||||
method = env['REQUEST_METHOD']
|
||||
self.logger.txn_id = trans_id
|
||||
try:
|
||||
# catch any errors in the pipeline
|
||||
@ -101,7 +100,10 @@ class CatchErrorsContext(WSGIContext):
|
||||
# the socket. In that case, we truncate the response body at N bytes
|
||||
# and raise an exception to stop any more bytes from being
|
||||
# generated and also to kill the TCP connection.
|
||||
if self._response_headers:
|
||||
if env['REQUEST_METHOD'] == 'HEAD':
|
||||
resp = enforce_byte_count(resp, 0)
|
||||
|
||||
elif self._response_headers:
|
||||
content_lengths = [val for header, val in self._response_headers
|
||||
if header.lower() == "content-length"]
|
||||
if len(content_lengths) == 1:
|
||||
@ -110,9 +112,7 @@ class CatchErrorsContext(WSGIContext):
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
resp = enforce_byte_count(
|
||||
resp,
|
||||
0 if method == 'HEAD' else content_length)
|
||||
resp = enforce_byte_count(resp, content_length)
|
||||
|
||||
# make sure the response has the trans_id
|
||||
if self._response_headers is None:
|
||||
|
@ -155,7 +155,6 @@ class GetContext(WSGIContext):
|
||||
con_resp = con_req.get_response(self.dlo.app)
|
||||
if not is_success(con_resp.status_int):
|
||||
if req.method == 'HEAD':
|
||||
close_if_possible(con_resp.app_iter)
|
||||
con_resp.body = ''
|
||||
return con_resp, None
|
||||
with closing_if_possible(con_resp.app_iter):
|
||||
|
@ -316,6 +316,7 @@ def _resp_body_property():
|
||||
value = value.encode('utf-8')
|
||||
if isinstance(value, str):
|
||||
self.content_length = len(value)
|
||||
close_if_possible(self._app_iter)
|
||||
self._app_iter = None
|
||||
self._body = value
|
||||
|
||||
@ -400,6 +401,7 @@ def _resp_app_iter_property():
|
||||
elif value is not None:
|
||||
self.content_length = None
|
||||
self._body = None
|
||||
close_if_possible(self._app_iter)
|
||||
self._app_iter = value
|
||||
|
||||
return property(getter, setter,
|
||||
@ -1115,6 +1117,7 @@ class Response(object):
|
||||
self.conditional_response = conditional_response
|
||||
self._conditional_etag = conditional_etag
|
||||
self.request = request
|
||||
self._app_iter = None
|
||||
self.body = body
|
||||
self.app_iter = app_iter
|
||||
self.response_iter = None
|
||||
|
Loading…
Reference in New Issue
Block a user