Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 364e233

Browse files
committed
Strip the connection header.
1 parent 7b02d32 commit 364e233

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

hyper/http20/connection.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,25 @@ def putheader(self, header, argument, stream_id=None):
265265
to be sent when you call
266266
:meth:`endheaders() <hyper.HTTP20Connection.endheaders>`.
267267
268+
This method ensures that headers conform to the HTTP/2 specification.
269+
In particular, it strips out the ``Connection`` header, as that header
270+
is no longer valid in HTTP/2. This is to make it easy to write code
271+
that runs correctly in both HTTP/1.1 and HTTP/2.
272+
268273
:param header: The name of the header.
269274
:param argument: The value of the header.
270275
:param stream_id: (optional) The stream ID of the request to add the
271276
header to.
272277
:returns: Nothing.
273278
"""
274279
stream = self._get_stream(stream_id)
280+
281+
# Initially, strip the Connection header. Note that we do this after
282+
# the call to `_get_stream` to ensure that we don't accidentally hide
283+
# bugs just because the user sent a connection header.
284+
if header.lower() == 'connection':
285+
return
286+
275287
stream.add_header(header, argument)
276288

277289
return

0 commit comments

Comments
 (0)