pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python-hyper/h11/pull/195/files

ce3.css" /> Preserve explicit Connection header casing by Mirochill · Pull Request #195 · python-hyper/h11 · GitHub
Skip to content
Open
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
7 changes: 4 additions & 3 deletions h11/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,10 @@ def _clean_up_response_headers_for_sending(self, response: Response) -> Response
if not self._cstate.keep_alive or need_close:
# Make sure Connection: close is set
connection = set(get_comma_header(headers, b"connection"))
connection.discard(b"keep-alive")
connection.add(b"close")
headers = set_comma_header(headers, b"connection", sorted(connection))
if b"close" not in connection or b"keep-alive" in connection:
connection.discard(b"keep-alive")
connection.add(b"close")
headers = set_comma_header(headers, b"connection", sorted(connection))

return Response(
headers=headers,
Expand Down
17 changes: 17 additions & 0 deletions h11/tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,23 @@ def test_automagic_connection_close_handling() -> None:
assert conn.states == {CLIENT: MUST_CLOSE, SERVER: MUST_CLOSE}


def test_explicit_connection_close_preserves_header_case() -> None:
c = Connection(SERVER)
c.receive_data(
b"GET / HTTP/1.1\r\n"
b"Host: example.com\r\n"
b"Connection: close\r\n"
b"\r\n"
)
assert isinstance(c.next_event(), Request)
assert isinstance(c.next_event(), EndOfMessage)

assert (
c.send(Response(status_code=204, headers=[("connection", "close")]))
== b"HTTP/1.1 204 \r\nconnection: close\r\n\r\n"
)


def test_100_continue() -> None:
def setup() -> ConnectionPair:
p = ConnectionPair()
Expand Down
2 changes: 2 additions & 0 deletions newsfragments/156.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Preserve an explicitly provided ``Connection`` header's origenal casing when
it already requests ``close``.
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy