Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions proxy/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,13 @@ def build_http_response(
line.append(reason)
if headers is None:
headers = {}
has_content_length = False
has_transfer_encoding = False
for k, _ in headers.items():
if k.lower() == b'content-length':
has_content_length = True
if k.lower() == b'transfer-encoding':
has_transfer_encoding = True
if body is not None and \
not has_transfer_encoding and \
not has_content_length:
headers[b'Content-Length'] = bytes_(len(body))
break
if not has_transfer_encoding:
headers[b'Content-Length'] = bytes_(len(body)) if body else b'0'
return build_http_pkt(line, headers, body, conn_close)


Expand Down
1 change: 1 addition & 0 deletions tests/http/exceptions/test_http_request_rejected.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_status_code_response(self) -> None:
self.assertEqual(
e.response(self.request), CRLF.join([
b'HTTP/1.1 200 OK',
b'Content-Length: 0',
b'Connection: close',
CRLF,
]),
Expand Down
2 changes: 2 additions & 0 deletions tests/http/parser/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def test_build_response(self) -> None:
okResponse(protocol_version=b'HTTP/1.1'),
CRLF.join([
b'HTTP/1.1 200 OK',
b'Content-Length: 0',
CRLF,
]),
)
Expand All @@ -157,6 +158,7 @@ def test_build_response(self) -> None:
CRLF.join([
b'HTTP/1.1 200 OK',
b'key: value',
b'Content-Length: 0',
CRLF,
]),
)
Expand Down