1111 HTTP_RAW_PUT_CONTRACT ,
1212 HttpContracts ,
1313)
14+ from helpers .helpers import HTTPHelpers
1415from pyoaev .helpers import OpenAEVConfigHelper , OpenAEVInjectorHelper
1516
1617
@@ -43,24 +44,6 @@ def __init__(self):
4344 self .config , open ("img/icon-http.png" , "rb" )
4445 )
4546
46- @staticmethod
47- def _request_data_parts_body (request_data ):
48- parts = request_data ["injection" ]["inject_content" ]["parts" ]
49- keys = list (map (lambda p : p ["key" ], parts ))
50- values = list (map (lambda p : p ["value" ], parts ))
51- return dict (zip (keys , values ))
52-
53- @staticmethod
54- def _response_parsing (response ):
55- success = 200 <= response .status_code < 300
56- success_status = "SUCCESS" if success else "ERROR"
57- return {
58- "url" : response .url ,
59- "code" : response .status_code ,
60- "status" : success_status ,
61- "message" : response .text ,
62- }
63-
6447 def attachments_to_files (self , request_data ):
6548 documents = request_data ["injection" ].get ("inject_documents" , [])
6649 attachments = list (filter (lambda d : d ["document_attached" ] is True , documents ))
@@ -73,7 +56,9 @@ def attachments_to_files(self, request_data):
7356
7457 def http_execution (self , data : Dict ):
7558 # Build headers
76- inject_headers = data ["injection" ]["inject_content" ].get ("headers" , [])
59+ inject_headers = HTTPHelpers .parse_headers (
60+ data ["injection" ]["inject_content" ].get ("headers" , [])
61+ )
7762 headers = {}
7863 for header_definition in inject_headers :
7964 headers [header_definition ["key" ]] = header_definition ["value" ]
@@ -93,35 +78,35 @@ def http_execution(self, data: Dict):
9378 # Get
9479 if inject_contract == HTTP_GET_CONTRACT :
9580 response = session .get (url = url , headers = headers )
96- return self . _response_parsing (response )
81+ return HTTPHelpers . response_parsing (response )
9782 # Post
9883 if inject_contract == HTTP_RAW_POST_CONTRACT :
9984 body = data ["injection" ]["inject_content" ]["body" ]
10085 response = session .post (
10186 url = url , headers = headers , data = body , files = http_files
10287 )
103- return self . _response_parsing (response )
88+ return HTTPHelpers . response_parsing (response )
10489 # Put
10590 if inject_contract == HTTP_RAW_PUT_CONTRACT :
10691 body = data ["injection" ]["inject_content" ]["body" ]
10792 response = session .put (
10893 url = url , headers = headers , data = body , files = http_files
10994 )
110- return self . _response_parsing (response )
95+ return HTTPHelpers . response_parsing (response )
11196 # Form Post
11297 if inject_contract == HTTP_FORM_POST_CONTRACT :
113- body = self . _request_data_parts_body (data )
98+ body = HTTPHelpers . request_data_parts_body (data )
11499 response = session .post (
115100 url = url , headers = headers , data = body , files = http_files
116101 )
117- return self . _response_parsing (response )
102+ return HTTPHelpers . response_parsing (response )
118103 # Form Put
119104 if inject_contract == HTTP_FORM_PUT_CONTRACT :
120- body = self . _request_data_parts_body (data )
105+ body = HTTPHelpers . request_data_parts_body (data )
121106 response = session .put (
122107 url = url , headers = headers , data = body , files = http_files
123108 )
124- return self . _response_parsing (response )
109+ return HTTPHelpers . response_parsing (response )
125110 # Nothing supported
126111 return {
127112 "code" : 400 ,
0 commit comments