|
@@ -43,7 +43,7 @@ def set_flex_response(client_addr, flex_host, flow): |
|
|
headers = flow.request.headers |
|
|
headers = flow.request.headers |
|
|
headers[HEADER_FLEX_AUTH] = router['auth'] |
|
|
headers[HEADER_FLEX_AUTH] = router['auth'] |
|
|
proxy_url = router['proxyUrl'] |
|
|
proxy_url = router['proxyUrl'] |
|
|
proxies = { "http": proxy_url, "https": proxy_url } |
|
|
|
|
|
|
|
|
proxies = {"http": proxy_url, "https": proxy_url} |
|
|
|
|
|
|
|
|
# send request to flex router |
|
|
# send request to flex router |
|
|
if bubble_log.isEnabledFor(DEBUG): |
|
|
if bubble_log.isEnabledFor(DEBUG): |
|
@@ -58,7 +58,9 @@ def set_flex_response(client_addr, flex_host, flow): |
|
|
# Parse the response, we have to do this raw to capture the full status line |
|
|
# Parse the response, we have to do this raw to capture the full status line |
|
|
|
|
|
|
|
|
# Status line |
|
|
# Status line |
|
|
next_bytes = response.raw.read(16384) # enough to read all headers |
|
|
|
|
|
|
|
|
# 16K should be enough to capture status line and all headers |
|
|
|
|
|
# see https://stackoverflow.com/questions/686217/maximum-on-http-header-values |
|
|
|
|
|
next_bytes = response.raw.read(16384) |
|
|
response_text = next_bytes.decode() |
|
|
response_text = next_bytes.decode() |
|
|
lines = response_text.splitlines() |
|
|
lines = response_text.splitlines() |
|
|
status_line = lines[0] |
|
|
status_line = lines[0] |
|
@@ -83,12 +85,13 @@ def set_flex_response(client_addr, flex_host, flow): |
|
|
bytes_consumed = bytes_consumed + len(header_line) + 1 |
|
|
bytes_consumed = bytes_consumed + len(header_line) + 1 |
|
|
if end_of_headers: |
|
|
if end_of_headers: |
|
|
break |
|
|
break |
|
|
next_bytes = response.raw.read(8192) |
|
|
|
|
|
|
|
|
next_bytes = response.raw.read(8192) # wow, headers are big! continue reading in 8K chunks |
|
|
next_text = lines[-1] + '\n' + next_bytes.decode() |
|
|
next_text = lines[-1] + '\n' + next_bytes.decode() |
|
|
lines = next_text.splitlines() |
|
|
lines = next_text.splitlines() |
|
|
|
|
|
|
|
|
flow.response.headers = response_headers |
|
|
flow.response.headers = response_headers |
|
|
|
|
|
|
|
|
# Body -- prepend remainder left over from parsing headers |
|
|
|
|
|
|
|
|
# Body |
|
|
|
|
|
# Determine the remainder left over from parsing headers, send that first |
|
|
remainder = next_bytes[bytes_consumed:] |
|
|
remainder = next_bytes[bytes_consumed:] |
|
|
flow.response.stream = prepend_remainder_to_stream(remainder, response.raw) |
|
|
flow.response.stream = prepend_remainder_to_stream(remainder, response.raw) |