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
1 change: 1 addition & 0 deletions CHANGES/10945.feature.rst
1 change: 1 addition & 0 deletions CHANGES/10961.feature.rst
1 change: 1 addition & 0 deletions CHANGES/10962.feature.rst
1 change: 1 addition & 0 deletions CHANGES/10968.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed double compression issue when :py:meth:`~aiohttp.web.StreamResponse.enable_compression` is called on a response with pre-existing Content-Encoding header -- by :user:`bdraco`.
1 change: 1 addition & 0 deletions CHANGES/10968.feature.rst
1 change: 1 addition & 0 deletions CHANGES/10972.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgraded to LLHTTP 9.3.0 -- by :user:`Dreamsorcerer`.
7 changes: 7 additions & 0 deletions aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ def enable_compression(
strategy: Optional[int] = None,
) -> None:
"""Enables response compression encoding."""
# Don't enable compression if content is already encoded.
# This prevents double compression and provides a safe, predictable behavior
# without breaking existing code that may call enable_compression() on
# responses that already have Content-Encoding set (e.g., FileResponse
# serving pre-compressed files).
if hdrs.CONTENT_ENCODING in self._headers:
return
self._compression = True
self._compression_force = force
self._compression_strategy = strategy
Expand Down
1 change: 1 addition & 0 deletions docs/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The page contains all information about aiohttp Client API:

Quickstart <client_quickstart>
Advanced Usage <client_advanced>
Client Middleware Cookbook <client_middleware_cookbook>
Reference <client_reference>
Tracing Reference <tracing_reference>
The aiohttp Request Lifecycle <http_request_lifecycle>
18 changes: 17 additions & 1 deletion docs/client_advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ Client Middleware
The client supports middleware to intercept requests and responses. This can be
useful for authentication, logging, request/response modification, and retries.

For practical examples and common middleware patterns, see the :ref:`aiohttp-client-middleware-cookbook`.

Creating Middleware
^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -713,12 +715,26 @@ make all sockets respect 9*7200 = 18 hours::
import socket

def socket_factory(addr_info):
family, type_, proto, _, _, _ = addr_info
family, type_, proto, _, _ = addr_info
sock = socket.socket(family=family, type=type_, proto=proto)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, True)
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 7200)
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 9)
return sock

conn = aiohttp.TCPConnector(socket_factory=socket_factory)

``socket_factory`` may also be used for binding to the specific network
interface on supported platforms::

def socket_factory(addr_info):
family, type_, proto, _, _ = addr_info
sock = socket.socket(family=family, type=type_, proto=proto)
sock.setsockopt(
socket.SOL_SOCKET, socket.SO_BINDTODEVICE, b'eth0'
)
return sock

conn = aiohttp.TCPConnector(socket_factory=socket_factory)


Expand Down
Loading
Loading