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
2 changes: 1 addition & 1 deletion src/pyrobusta/bindings/http_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def _run_state_machine(self):
await self._response_handler(self._engine.resp_handler)

async def _response_handler(self, resp_handler):
if "closure" == type(resp_handler).__name__:
if callable(resp_handler):
if self._engine.get_response_header(b"transfer-encoding") == b"chunked":
for is_finished in resp_handler(self._send_buf):
await self.write(b"%x\r\n" % self._send_buf.size())
Expand Down
8 changes: 4 additions & 4 deletions src/pyrobusta/protocol/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,7 @@ def _get_mp_boundary(headers: dict) -> str:
and return the boundary value.
"""
content_type = headers.get("content-type")
if not content_type or not content_type.lower().startswith(
"multipart/form-data"
):
if not content_type or not content_type.lower().startswith("multipart/"):
return None

parts = content_type.split(";")
Expand Down Expand Up @@ -440,6 +438,7 @@ def set_response_header(self, key: bytes, value: bytes):
:param key: HTTP header key
:param value: HTTP header value
"""
key = key.lower()
if (
key in self.resp_headers
and (index := self.resp_headers.index(key)) % 2 == 0
Expand Down Expand Up @@ -810,7 +809,8 @@ def _app_endpoint_st(self, rx):
return

dtype, data = callback_response
if dtype.startswith("multipart/"):
if dtype.startswith("multipart/") and callable(data):
self.set_response_header(b"transfer-encoding", b"chunked")
self.state = lambda _rx: self._generate_multipart_response(_rx, data, dtype)
return

Expand Down
6 changes: 3 additions & 3 deletions src/pyrobusta/protocol/http_file_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def _traverse_dir(tx):
tx.write(b",")

file_stat = stat(it)
obj = dumps(
data = dumps(
{
"path": it,
"size": str(file_stat[6]),
Expand All @@ -263,11 +263,11 @@ def _traverse_dir(tx):
).encode("ascii")

written = 0
while written < len(obj):
while written < len(data):
to_write = tx.capacity - tx.size()
if not to_write:
raise BufferError()
tx.write(obj[written : written + to_write])
tx.write(data[written : written + to_write])
written += to_write
yield False
tx.write(b"]\r\n")
Expand Down
Loading