Skip to content

Commit fce40f0

Browse files
authored
compress option for serve_static_file utility method (#1405)
* `compress` option for `serve_static_file` utility method * Pin to `macos-12` for now * Change default to `True` (old default behavior)
1 parent 8b929f0 commit fce40f0

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

.github/workflows/test-library.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ jobs:
439439
# max-parallel: 4
440440
matrix:
441441
os:
442-
- macOS-latest
442+
- macOS-12
443443
- Ubuntu-20.04
444444
- Windows-latest
445445
python:
@@ -694,7 +694,7 @@ jobs:
694694
name: 📊 Node ${{ matrix.node }} @ ${{ matrix.os }}
695695
strategy:
696696
matrix:
697-
os: [ubuntu-20.04, windows-latest, macOS-latest]
697+
os: [ubuntu-20.04, windows-latest, macOS-12]
698698
node: ['10.x', '11.x', '12.x']
699699
# max-parallel: 4
700700
fail-fast: false

proxy/common/constants.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ def _env_threadless_compliant() -> bool:
125125
DEFAULT_HTTPS_PROXY_ACCESS_LOG_FORMAT = '{client_ip}:{client_port} - ' + \
126126
'{request_method} {server_host}:{server_port} - ' + \
127127
'{response_bytes} bytes - {connection_time_ms}ms'
128-
DEFAULT_REVERSE_PROXY_ACCESS_LOG_FORMAT = '{client_ip}:{client_port} - ' + \
129-
'{request_method} {request_path} -> {upstream_proxy_pass} - {connection_time_ms}ms'
128+
DEFAULT_REVERSE_PROXY_ACCESS_LOG_FORMAT = (
129+
"{client_ip}:{client_port} - "
130+
+ "{request_method} {request_path} - {request_ua} -> "
131+
+ "{upstream_proxy_pass} - {connection_time_ms}ms"
132+
)
130133
DEFAULT_NUM_ACCEPTORS = 0
131134
DEFAULT_NUM_WORKERS = 0
132135
DEFAULT_OPEN_FILE_LIMIT = 1024

proxy/http/handler.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def handle_data(self, data: memoryview) -> Optional[bool]:
181181
elif self.plugin:
182182
self.plugin.on_client_data(data)
183183
except HttpProtocolException as e:
184-
logger.info('HttpProtocolException: %s' % e)
184+
logger.warning('HttpProtocolException: %s' % e)
185185
response: Optional[memoryview] = e.response(self.request)
186186
if response:
187187
self.work.queue(response)
@@ -209,9 +209,10 @@ async def handle_writables(self, writables: Writables) -> bool:
209209
'BrokenPipeError when flushing buffer for client',
210210
)
211211
return True
212-
except OSError:
213-
logger.warning( # pragma: no cover
212+
except OSError as exc:
213+
logger.exception( # pragma: no cover
214214
'OSError when flushing buffer to client',
215+
exc_info=exc,
215216
)
216217
return True
217218
return False

proxy/http/server/plugin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ def __init__(
4747
self.upstream_conn_pool = upstream_conn_pool
4848

4949
@staticmethod
50-
def serve_static_file(path: str, min_compression_length: int) -> memoryview:
50+
def serve_static_file(
51+
path: str,
52+
min_compression_length: int,
53+
compress: bool = True,
54+
) -> memoryview:
5155
try:
5256
with open(path, 'rb') as f:
5357
content = f.read()
@@ -61,6 +65,7 @@ def serve_static_file(path: str, min_compression_length: int) -> memoryview:
6165
return okResponse(
6266
content=content,
6367
headers=headers,
68+
compress=compress,
6469
min_compression_length=min_compression_length,
6570
# TODO: Should we really close or take advantage of keep-alive?
6671
conn_close=True,

0 commit comments

Comments
 (0)