aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
Diffstat (limited to 'netlib')
-rw-r--r--netlib/http/__init__.py1
-rw-r--r--netlib/http/http1/protocol.py22
-rw-r--r--netlib/http/http2/protocol.py20
-rw-r--r--netlib/http/semantics.py31
4 files changed, 54 insertions, 20 deletions
diff --git a/netlib/http/__init__.py b/netlib/http/__init__.py
index 9b4b0e6b..b01afc6d 100644
--- a/netlib/http/__init__.py
+++ b/netlib/http/__init__.py
@@ -1,2 +1,3 @@
+from . import *
from exceptions import *
from semantics import *
diff --git a/netlib/http/http1/protocol.py b/netlib/http/http1/protocol.py
index 401654c1..8d631a13 100644
--- a/netlib/http/http1/protocol.py
+++ b/netlib/http/http1/protocol.py
@@ -11,25 +11,10 @@ from ..exceptions import *
class HTTP1Protocol(object):
- # TODO: make this a regular class - just like Response
- Request = collections.namedtuple(
- "Request",
- [
- "form_in",
- "method",
- "scheme",
- "host",
- "port",
- "path",
- "httpversion",
- "headers",
- "content"
- ]
- )
-
def __init__(self, tcp_handler):
self.tcp_handler = tcp_handler
+
def get_request_line(self):
"""
Get a line, possibly preceded by a blank.
@@ -40,6 +25,7 @@ class HTTP1Protocol(object):
line = self.tcp_handler.rfile.readline()
return line
+
def read_headers(self):
"""
Read a set of headers.
@@ -175,6 +161,7 @@ class HTTP1Protocol(object):
return None
return host, port, httpversion
+
@classmethod
def parse_init_proxy(self, line):
v = self.parse_init(line)
@@ -188,6 +175,7 @@ class HTTP1Protocol(object):
scheme, host, port, path = parts
return method, scheme, host, port, path, httpversion
+
@classmethod
def parse_init_http(self, line):
"""
@@ -425,7 +413,7 @@ class HTTP1Protocol(object):
True
)
- return self.Request(
+ return http.Request(
form_in,
method,
scheme,
diff --git a/netlib/http/http2/protocol.py b/netlib/http/http2/protocol.py
index 0d6eac85..1dfdda21 100644
--- a/netlib/http/http2/protocol.py
+++ b/netlib/http/http2/protocol.py
@@ -187,11 +187,25 @@ class HTTP2Protocol(object):
self._create_body(body, stream_id)))
def read_response(self, *args):
- stream_id_, headers, body = self._receive_transmission()
- return http.Response("HTTP/2", headers[':status'], "", headers, body)
+ stream_id, headers, body = self._receive_transmission()
+
+ response = http.Response("HTTP/2", headers[':status'], "", headers, body)
+ response.stream_id = stream_id
+ return response
def read_request(self):
- return self._receive_transmission()
+ stream_id, headers, body = self._receive_transmission()
+
+ form_in = ""
+ method = headers.get(':method', '')
+ scheme = headers.get(':scheme', '')
+ host = headers.get(':host', '')
+ port = '' # TODO: parse port number?
+ path = headers.get(':path', '')
+
+ request = http.Request(form_in, method, scheme, host, port, path, "HTTP/2", headers, body)
+ request.stream_id = stream_id
+ return request
def _receive_transmission(self):
body_expected = True
diff --git a/netlib/http/semantics.py b/netlib/http/semantics.py
index a62c93e3..9a010318 100644
--- a/netlib/http/semantics.py
+++ b/netlib/http/semantics.py
@@ -7,6 +7,37 @@ import urlparse
from .. import utils
+class Request(object):
+
+ def __init__(
+ self,
+ form_in,
+ method,
+ scheme,
+ host,
+ port,
+ path,
+ httpversion,
+ headers,
+ content,
+ ):
+ self.form_in = form_in
+ self.method = method
+ self.scheme = scheme
+ self.host = host
+ self.port = port
+ self.path = path
+ self.httpversion = httpversion
+ self.headers = headers
+ self.content = content
+
+ def __eq__(self, other):
+ return self.__dict__ == other.__dict__
+
+ def __repr__(self):
+ return "Request(%s - %s, %s)" % (self.method, self.host, self.path)
+
+
class Response(object):
def __init__(