Skip to content
Merged
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
15 changes: 9 additions & 6 deletions src/templates/python/proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
# 15-minute timeout (matching Java)
SOCKET_TIMEOUT_SECONDS = 15 * 60

HOP_BY_HOP_HEADERS = frozenset({
'content-length', 'transfer-encoding', 'connection', 'keep-alive',
'proxy-connection', 'te', 'trailers', 'upgrade',
})


class ProxyHandler(BaseHTTPRequestHandler):
server_instance = None
Expand Down Expand Up @@ -174,16 +179,14 @@ def do_request(self, method, body=None):
response_body = response.content

try:
# Send response back with status code, headers and body
self.send_response(response.status_code)

# Strip Content-Length header since response_body may have been modified
# The HTTP server will calculate the correct length
response_headers = {key: val for key, val in response.headers.items()
if key.lower() != 'content-length'}
if key.lower() not in HOP_BY_HOP_HEADERS}
Comment on lines 182 to +183

self.send_response(response.status_code)
for key, val in response_headers.items():
self.send_header(key, val)
self.send_header('Content-Length', str(len(response_body)))
self.send_header('Connection', 'close')
self.end_headers()
self.wfile.write(response_body)
except Exception as send_error:
Expand Down
Loading