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