Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Chunked Transfer Encoding Error #329

Merged
merged 2 commits into from
Dec 19, 2024
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
26 changes: 20 additions & 6 deletions navigator/actions/zammad.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@
image_data = image # Ya es un objeto binario válido

expiring_date = datetime.now() + timedelta(days=2)
chunk_size = 16384
content_length = len(image_data)
# Crear y devolver la respuesta HTTP
response = StreamResponse(
status=200,
Expand All @@ -441,12 +443,24 @@
'Expires': expiring_date.strftime('%a, %d %b %Y %H:%M:%S GMT'),
}
)
response.content_length = len(image_data)
await response.prepare(request)
await response.write(image_data)
await response.write_eof()
return response
response.headers[
"Content-Range"
] = f"bytes 0-{chunk_size}/{content_length}"
try:
i = 0
await response.prepare(request)
while True:
chunk = image_data[i: i + chunk_size]
i += chunk_size
if not chunk:
break
await response.write(chunk)
Dismissed Show dismissed Hide dismissed
await response.drain() # deprecated
await response.write_eof()
return response
except Exception as e:
raise ConfigError(f"Error while writing attachment: {e}") from e
except KeyError as e:
raise ConfigError(f"Missing required header: {e}") from e
except Exception as e:
raise ConfigError(f"Unexpected error while fetching attachment: {e}") from e
raise ConfigError(f"Unexpected error while fetching attachment: {e}") from e
Loading