@@ -114,10 +114,11 @@ def __init__(
114114 # The presence of a message-body in a request is signaled by the
115115 # inclusion of a Content-Length or Transfer-Encoding header field in
116116 # the request's message-headers.
117- if self .stream .size is None :
117+ content_length : int | None = self .stream .size
118+ if content_length is None :
118119 self .headers = self .headers .copy_set ("Transfer-Encoding" , "chunked" )
119- elif self . stream . size > 0 :
120- self .headers = self .headers .copy_set ("Content-Length" , str (stream . size ))
120+ elif content_length > 0 :
121+ self .headers = self .headers .copy_set ("Content-Length" , str (content_length ))
121122
122123 async def read (self ):
123124 self .body = b"" .join ([part async for part in self .stream ])
@@ -160,10 +161,15 @@ def __init__(
160161 # MUST NOT include a message-body. All other responses do include a
161162 # message-body, although it MAY be of zero length.
162163 if code >= 200 and code != 204 and code != 304 :
163- if self .stream .size is None :
164+ content_length : int | None = self .stream .size
165+ if content_length is None :
164166 self .headers = self .headers .copy_set ("Transfer-Encoding" , "chunked" )
165167 else :
166- self .headers = self .headers .copy_set ("Content-Length" , str (stream .size ))
168+ self .headers = self .headers .copy_set ("Content-Length" , str (content_length ))
169+
170+ @property
171+ def reason_phrase (self ):
172+ return _codes .get (self .code , "Unknown Status Code" )
167173
168174 async def read (self ):
169175 self .body = b"" .join ([part async for part in self .stream ])
@@ -173,5 +179,4 @@ def close(self):
173179 self .stream = ClosedStream ()
174180
175181 def __repr__ (self ):
176- phrase = _codes .get (self .code , "UNKNOWN" )
177- return f"<Response [{ self .code } { phrase } ]>"
182+ return f"<Response [{ self .code } { self .reason_phrase } ]>"
0 commit comments