Fix on_header callback when not redirecting and no Content-Type present

This commit is contained in:
Erik Johnson 2017-10-10 11:24:57 -05:00
parent bd879eb66e
commit 425ede4b84
No known key found for this signature in database
GPG Key ID: 5E5583C437808F3F

View File

@ -622,12 +622,19 @@ class Client(object):
def on_header(hdr): def on_header(hdr):
if write_body[1] is not False and write_body[2] is None: if write_body[1] is not False and write_body[2] is None:
if not hdr.strip() and 'Content-Type' not in write_body[1]: if not hdr.strip() and 'Content-Type' not in write_body[1]:
# We've reached the end of the headers and not yet if write_body[0] is True:
# found the Content-Type. Reset write_body[0] so that # We are not following a redirect (initial response
# we properly follow the redirect. Note that slicing is # was a 200 OK). So there is no need to reset
# used below to ensure that we re-use the same list # write_body[0], but we do need to set the encoding
# rather than creating a new one. # since no Content-Type was present in the headers
write_body[0:2] = (None, False) # to tell us which to use.
write_body[2] = 'utf-8'
else:
# We are following a redirect, so we need to reset
# write_body[0] so that we properly follow it.
write_body[0] = None
# We don't need the HTTPHeaders object anymore
write_body[1] = False
return return
# Try to find out what content type encoding is used if # Try to find out what content type encoding is used if
# this is a text file # this is a text file