Repository navigation
Conversation
|
Thanks for raising this PR! |
| # respond on a stream the peer opened, or on one it reserved with | ||
| # PUSH_PROMISE: both already exist in ``self.streams``. | ||
| if not self.config.client_side and stream_id not in self.streams: | ||
| msg = f"Server cannot open stream {stream_id} by sending headers." |
There was a problem hiding this comment.
please remove the stream id from the error message - the statement should be true for all stream IDs, not just this one specific one.
| msg = f"Server cannot open stream {stream_id} by sending headers." | |
| msg = f"Servers cannot open new streams by sending a HEADERS frame." |
|
Please also add an appropriate CHANGELOG entry. |
Reword the comment to cite RFC 7540 sections 5.1.1 and 8.2 instead of overstating the RFC. Drop the stream id from the error message so it applies to all stream IDs, and add a CHANGELOG entry.
|
Thanks @Kriechi, both points addressed in On the RFC: you're right that it does not state "only clients may open a stream by sending HEADERS" verbatim. The supporting text is RFC 7540 Section 5.1.1 ("Streams initiated by a client MUST use odd-numbered stream identifiers; those initiated by the server MUST use even-numbered stream identifiers") together with Section 8.2, where the server creates an initiated stream by sending a PUSH_PROMISE frame and then sends HEADERS on the reserved stream. The stream-state diagram in Section 5.1 shows HEADERS on an idle stream or on a locally reserved stream. I rewrote the comment to cite Sections 5.1.1 and 8.2 and to describe the consequence rather than claim a quote. I also removed the stream id from the error message, as suggested: Verification: |
H2Connection.send_headersdocumented that "It is a protocol error for a server to open a stream by sending headers", but the implementation created the stream regardless of connection side: a fresh server connection could send HEADERS on an even-numbered stream and open it. A server-initiated stream is only legal after PUSH_PROMISE, whichpush_stream()handles.A guard in
send_headersnow raisesProtocolErrorwhen the server sends HEADERS on a stream not already inself.streams, before any state or output is mutated. Client behavior, upgrade stream 1, and PUSH_PROMISE-reserved streams are unchanged.Verification: base source fails the new server test (
DID NOT RAISE); with the fixtests/test_basic_logic.pyis 392 passed and the full suite is 1687 passed.ruff checkon source andmypy --strict-bytespass; three lint errors in the test file are pre-existing on base. A server upgrade sanity check also passes.