diff options
author | Alvaro Neira Ayuso <aneira@soleta.eu> | 2019-12-12 14:47:41 +0100 |
---|---|---|
committer | Alvaro Neira Ayuso <alvaroneay@gmail.com> | 2020-01-19 19:50:44 +0100 |
commit | bfdeae840c95fb9da504af795179be65c6286326 (patch) | |
tree | a2b9f9fdf09eef5a4975ee295636ae5383cc9893 /src/ogClient.py | |
parent | 076e15bb299dbcc1f8cc0d6f260c26f39d81f983 (diff) |
Add HTTP parser support
The new OpenGnsys support to communicate server and client side will be
HTTP. This new class allows us the support for parsing all the message received
from the server in HTTP format.
Diffstat (limited to 'src/ogClient.py')
-rw-r--r-- | src/ogClient.py | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/src/ogClient.py b/src/ogClient.py index 296c03c..b54d736 100644 --- a/src/ogClient.py +++ b/src/ogClient.py @@ -2,9 +2,8 @@ import errno import select
import socket
import time
-import httplib
-from mimetools import Message
-from StringIO import StringIO
+
+from HTTPParser import *
from enum import Enum
class State(Enum):
@@ -66,8 +65,8 @@ class ogClient: self.sock.close()
self.connect()
- print "received " + data
self.data = self.data + data
+ httpparser = HTTPParser()
if not self.trailer:
if self.data.find("\r\n") > 0:
@@ -75,18 +74,13 @@ class ogClient: request_line, headers_alone = self.data.split('\n', 1)
headers = Message(StringIO(headers_alone))
- print "DEBUG: \r\n trailer received"
- print "DEBUG: HTTP keys are " + str(headers.keys())
-
if 'content-length' in headers.keys():
self.content_len = int(headers['content-length'])
self.trailer = True
if self.trailer and len(self.data) >= self.content_len:
- #
- # TODO: handle request here
- #
+ httpparser.parser(self.data)
self.sock.send("HTTP/1.0 200 OK\r\n\r\n")
@@ -94,4 +88,3 @@ class ogClient: self.data = ""
self.content_len = 0
self.trailer = False
- print "DEBUG: request has been processed!"
|