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

Commit 00bc075

Browse files
committed
Handle :status header better.
This resolves #16.
1 parent 0c5a311 commit 00bc075

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

hyper/http20/response.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ def __init__(self, headers, stream):
1919
#: HTTP/2.0, and so is always the empty string.
2020
self.reason = ''
2121

22+
#: The status code returned by the server.
23+
self.status = int(headers[':status'])
24+
del headers[':status']
25+
2226
# The response headers. These are determined upon creation, assigned
2327
# once, and never assigned again.
2428
# This conversion to dictionary is unwise, as there may be repeated
@@ -70,10 +74,3 @@ def fileno(self):
7074
Return the ``fileno`` of the underlying socket.
7175
"""
7276
pass
73-
74-
@property
75-
def status(self):
76-
"""
77-
Status code returned by the server.
78-
"""
79-
return int(self._headers[':status'])

test/test_hyper.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from hyper.http20.stream import (
1212
Stream, STATE_HALF_CLOSED_LOCAL, STATE_OPEN, MAX_CHUNK, STATE_CLOSED
1313
)
14+
from hyper.http20.response import HTTP20Response
1415
import pytest
1516
from io import BytesIO
1617

@@ -1022,6 +1023,16 @@ def inner():
10221023
assert len(out_frames) == 1
10231024
assert s.state == STATE_CLOSED
10241025

1026+
1027+
class TestResponse(object):
1028+
def test_status_is_stripped_from_headers(self):
1029+
headers = {':status': '200'}
1030+
resp = HTTP20Response(headers, None)
1031+
1032+
assert resp.status == 200
1033+
assert resp.getheaders() == []
1034+
1035+
10251036
# Some utility classes for the tests.
10261037
class NullEncoder(object):
10271038
def encode(headers):

0 commit comments

Comments
 (0)