Commit bc07ab25 authored by Łukasz Nowak's avatar Łukasz Nowak

recurls: Switch response headers to HTTPMessage

CaseInsensitiveDict resulted with risky situations.
parent c41d4ef1
...@@ -2,7 +2,6 @@ import json ...@@ -2,7 +2,6 @@ import json
import urllib.parse import urllib.parse
import tempfile import tempfile
import subprocess import subprocess
from requests.structures import CaseInsensitiveDict
import gzip import gzip
import os import os
import http.client import http.client
...@@ -136,17 +135,14 @@ class Recurls(object): ...@@ -136,17 +135,14 @@ class Recurls(object):
raise raise
with open(response_header_file) as fh: with open(response_header_file) as fh:
response.header_text = fh.read() response.header_text = fh.read()
response.headers = CaseInsensitiveDict() response.headers = http.client.HTTPMessage()
for line in response.header_text.splitlines()[1:]: for line in response.header_text.splitlines()[1:]:
if line.strip(): if line.strip():
if ':' not in line: if ':' not in line:
continue continue
header, value = line.split(':', 1) header, value = line.split(':', 1)
value = value.strip() value = value.strip()
response.headers.setdefault(header, []) response.headers.add_header(header, value)
response.headers[header].append(value)
for header in response.headers.keys():
response.headers[header] = ', '.join(response.headers[header])
if response.headers.get('content-encoding') == 'gzip': if response.headers.get('content-encoding') == 'gzip':
with gzip.GzipFile(response_file) as fh: with gzip.GzipFile(response_file) as fh:
response.text = fh.read().decode() response.text = fh.read().decode()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment