Skip to content

Commit

Permalink
added header support
Browse files Browse the repository at this point in the history
  • Loading branch information
c7h committed Jun 11, 2022
1 parent b19c336 commit 1699d0e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions restler/engine/transport_layer/messaging.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

""" Transport layer fuctionality using python sockets. """
""" Transport layer functionality using python sockets. """
from __future__ import print_function
from abc import ABCMeta, abstractmethod
import ssl
Expand Down Expand Up @@ -67,8 +67,7 @@ def __init__(self, connection_settings: Dict) -> None:
self.connection_settings = connection_settings

self.ignore_decoding_failures = Settings().ignore_decoding_failures



@abstractmethod
def __del__(self):
pass
Expand All @@ -77,7 +76,6 @@ def __del__(self):
def sendRecv(self, message: str, req_timeout_sec: int) -> Tuple[bool, str]:
pass


def _get_method_from_message(self, message):
end_of_method_idx = message.find(" ")
method_name = message[0:end_of_method_idx]
Expand All @@ -94,8 +92,18 @@ def _get_uri_segment_from_message(self, message):
segment_end_index = message[segment_start_index+1:].find(' ') + segment_start_index+1
segment = message[segment_start_index+1:segment_end_index]
return segment

def _get_headers_from_message(self, message) -> Dict:
# FIXME: ugly
header_index = message.find('\r\n')
payload_index = message.find(DELIM)


headers = message[header_index+2:payload_index]
h = dict()
for line in headers.split('\r\n'):
k, v = line.split(':')
h[k.strip()] = v.strip()
return h


class Http2Sock(BaseSocket):
Expand All @@ -117,7 +125,6 @@ def __init__(self, connection_settings: Dict) -> None:
secure=self.connection_settings.use_ssl
)


def sendRecv(self, message: str, req_timeout_sec: int) -> Tuple[bool, str]:
super().sendRecv(message, req_timeout_sec)
method = self._get_method_from_message(message)
Expand All @@ -130,7 +137,7 @@ def sendRecv(self, message: str, req_timeout_sec: int) -> Tuple[bool, str]:
method,
url=uri_segment,
body=bytes(message_body, UTF8), #TODO: allow other encodings
#headers=self._get_header_from_message(message) # TODO: implement header support
headers=self._get_headers_from_message(message)
)

response = self.client.get_response()
Expand All @@ -139,7 +146,6 @@ def sendRecv(self, message: str, req_timeout_sec: int) -> Tuple[bool, str]:

return (True, res)


def __del__(self):
pass

Expand Down

0 comments on commit 1699d0e

Please sign in to comment.