-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessageHandler.py
More file actions
51 lines (44 loc) · 2.05 KB
/
Copy pathmessageHandler.py
File metadata and controls
51 lines (44 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#Goals
# Hold all request data as it's assembled
# Hold all response data as it's assembled
# Put that data in a dict so can be passed further up the chain
from h2.events import (
RequestReceived, ResponseReceived, DataReceived, RemoteSettingsChanged, StreamEnded,
StreamReset, SettingsAcknowledged,
)
class messageHandler():
def __init__(self):
self.requestFrames = []
self.responseFrames = []
def storeEvent(self, event, response=True):
if response == True:
response = self.packageResponseEvent(event)
self.responseFrames.append(response)
def packageResponseEvent(self, event):
if isinstance(event, RequestReceived):
return {"type": "RequestReceived", "stream_id": event.stream_id,
"headers": event.headers}
elif isinstance(event, DataReceived):
return {"type": "DataReceived",
"stream_id": event.stream_id,
"flow_controlled_length": event.flow_controlled_length,
"data": "Hello"}
elif isinstance(event, RemoteSettingsChanged):
return {"type": "RemoteSettingsChanged",
"changed_settings": event.changed_settings}
elif isinstance(event, StreamEnded):
return {"type": "StreamEnded", "stream_id" : event.stream_id}
# elif isinstance(event, StreamReset):
elif isinstance(event, SettingsAcknowledged):
return {"type": "SettingsAcknowledged",
"changed_settings": event.changed_settings}
elif isinstance(event, ResponseReceived):
return {"type": "ResponseReceived", "stream_id" : event.stream_id,
"headers": self.parse_response_headers_to_JSON(event)}
# return the header object as a series of pairs in dictionary
def parse_response_headers_to_JSON(self, event):
headers = event.headers
return_dict = {}
for header_pair in headers:
return_dict[header_pair[0]] = header_pair[1]
return return_dict