aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/http/semantics.py
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2015-08-05 21:32:53 +0200
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2015-08-10 20:34:27 +0200
commit690b8b4f4e00d60b373b5a1481930f21bbc5054a (patch)
treedd0091035e4027e792174cb2dcf63eb37afa0a56 /netlib/http/semantics.py
parentc2832ef72bd4eed485a1c8d4bcb732da69896444 (diff)
downloadmitmproxy-690b8b4f4e00d60b373b5a1481930f21bbc5054a.tar.gz
mitmproxy-690b8b4f4e00d60b373b5a1481930f21bbc5054a.tar.bz2
mitmproxy-690b8b4f4e00d60b373b5a1481930f21bbc5054a.zip
add move tests and code from mitmproxy
Diffstat (limited to 'netlib/http/semantics.py')
-rw-r--r--netlib/http/semantics.py43
1 files changed, 27 insertions, 16 deletions
diff --git a/netlib/http/semantics.py b/netlib/http/semantics.py
index e7ae2b5f..974fe6e6 100644
--- a/netlib/http/semantics.py
+++ b/netlib/http/semantics.py
@@ -7,7 +7,7 @@ import urllib
import urlparse
from .. import utils, odict
-from . import cookies
+from . import cookies, exceptions
from netlib import utils, encoding
HDR_FORM_URLENCODED = "application/x-www-form-urlencoded"
@@ -18,10 +18,10 @@ CONTENT_MISSING = 0
class ProtocolMixin(object):
- def read_request(self):
+ def read_request(self, *args, **kwargs): # pragma: no cover
raise NotImplemented
- def read_response(self):
+ def read_response(self, *args, **kwargs): # pragma: no cover
raise NotImplemented
def assemble(self, message):
@@ -32,14 +32,23 @@ class ProtocolMixin(object):
else:
raise ValueError("HTTP message not supported.")
- def assemble_request(self, request):
+ def assemble_request(self, request): # pragma: no cover
raise NotImplemented
- def assemble_response(self, response):
+ def assemble_response(self, response): # pragma: no cover
raise NotImplemented
class Request(object):
+ # This list is adopted legacy code.
+ # We probably don't need to strip off keep-alive.
+ _headers_to_strip_off = [
+ 'Proxy-Connection',
+ 'Keep-Alive',
+ 'Connection',
+ 'Transfer-Encoding',
+ 'Upgrade',
+ ]
def __init__(
self,
@@ -71,7 +80,6 @@ class Request(object):
self.timestamp_start = timestamp_start
self.timestamp_end = timestamp_end
-
def __eq__(self, other):
try:
self_d = [self.__dict__[k] for k in self.__dict__ if k not in ('timestamp_start', 'timestamp_end')]
@@ -114,7 +122,7 @@ class Request(object):
self.httpversion[1],
)
else:
- raise http.HttpError(400, "Invalid request form")
+ raise exceptions.HttpError(400, "Invalid request form")
def anticache(self):
"""
@@ -143,7 +151,7 @@ class Request(object):
if self.headers["accept-encoding"]:
self.headers["accept-encoding"] = [
', '.join(
- e for e in encoding.ENCODINGS if e in self.headers["accept-encoding"][0])]
+ e for e in encoding.ENCODINGS if e in self.headers.get_first("accept-encoding"))]
def update_host_header(self):
"""
@@ -317,12 +325,12 @@ class Request(object):
self.scheme, self.host, self.port, self.path = parts
@property
- def content(self):
+ def content(self): # pragma: no cover
# TODO: remove deprecated getter
return self.body
@content.setter
- def content(self, content):
+ def content(self, content): # pragma: no cover
# TODO: remove deprecated setter
self.body = content
@@ -343,6 +351,11 @@ class EmptyRequest(Request):
class Response(object):
+ _headers_to_strip_off = [
+ 'Proxy-Connection',
+ 'Alternate-Protocol',
+ 'Alt-Svc',
+ ]
def __init__(
self,
@@ -368,7 +381,6 @@ class Response(object):
self.timestamp_start = timestamp_start
self.timestamp_end = timestamp_end
-
def __eq__(self, other):
try:
self_d = [self.__dict__[k] for k in self.__dict__ if k not in ('timestamp_start', 'timestamp_end')]
@@ -393,7 +405,6 @@ class Response(object):
size=size
)
-
def get_cookies(self):
"""
Get the contents of all Set-Cookie headers.
@@ -430,21 +441,21 @@ class Response(object):
self.headers["Set-Cookie"] = values
@property
- def content(self):
+ def content(self): # pragma: no cover
# TODO: remove deprecated getter
return self.body
@content.setter
- def content(self, content):
+ def content(self, content): # pragma: no cover
# TODO: remove deprecated setter
self.body = content
@property
- def code(self):
+ def code(self): # pragma: no cover
# TODO: remove deprecated getter
return self.status_code
@code.setter
- def code(self, code):
+ def code(self, code): # pragma: no cover
# TODO: remove deprecated setter
self.status_code = code