File tree 1 file changed +5
-3
lines changed
1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -230,16 +230,18 @@ def request(
230
230
if not allow_redirects :
231
231
self .client .redirect_resonse_codes = old_redirect_response_codes
232
232
233
+ request_meta ["response_length" ] = 0 # default value, if length cannot be determined
234
+
233
235
# get the length of the content, but if the argument stream is set to True, we take
234
236
# the size from the content-length header, in order to not trigger fetching of the body
235
237
if stream :
236
- request_meta ["response_length" ] = int (response .headers .get ("response_length" ) or 0 )
238
+ if response .headers and "response_length" in response .headers :
239
+ request_meta ["response_length" ] = int (response .headers ["response_length" ])
237
240
else :
238
241
try :
239
- request_meta ["response_length" ] = len (response .content or "" )
242
+ request_meta ["response_length" ] = len (response .content ) if response . content else 0
240
243
except HTTPParseError as e :
241
244
request_meta ["response_time" ] = (time .perf_counter () - start_perf_counter ) * 1000
242
- request_meta ["response_length" ] = 0
243
245
request_meta ["exception" ] = e
244
246
self .environment .events .request .fire (** request_meta )
245
247
return response
You can’t perform that action at this time.
0 commit comments