9
9
from ..version import __version__
10
10
from ..proxy import Proxy
11
11
12
+ from .stringextension import StringExtension
12
13
from .httpendpoint import HttpEndpoint
13
14
from .injectionresponseparser import InjectionResponseParser
14
15
from .serialization .injectionrequest import InjectionRequest
@@ -28,7 +29,7 @@ class HttpRequestMethod(Enum):
28
29
PUT = 2
29
30
DELETE = 3
30
31
31
- def __init__ (self , method : HttpRequestMethod , endpoint : HttpEndpoint , timeout : int ):
32
+ def __init__ (self , method : HttpRequestMethod , endpoint : HttpEndpoint , timeout : int , authentication : str ):
32
33
"""
33
34
Creates a new instance of the HTTP Request class
34
35
:param method: the HTTP request method
@@ -40,6 +41,14 @@ def __init__(self, method: HttpRequestMethod, endpoint: HttpEndpoint, timeout: i
40
41
self ._endpoint = endpoint
41
42
self ._http_proxy = None
42
43
self ._timeout = timeout
44
+ self ._authentication = authentication
45
+ self ._headers = {
46
+ 'User-Agent' : self .__user_agent ,
47
+ 'Content-Type' : 'application/json; charset=utf-8' ,
48
+ 'Accept' : 'application/json' ,
49
+ }
50
+ if not StringExtension .is_none_or_white_space (authentication ):
51
+ self ._headers ["Authorization" ] = "Bearer " + authentication
43
52
44
53
@property
45
54
def __user_agent (self ):
@@ -108,7 +117,7 @@ def send_async_request(self, request: InjectionRequest, on_success_callback, on_
108
117
"""
109
118
110
119
try :
111
-
120
+ print ( request )
112
121
th = threading .Thread (target = self .__queue_request ,
113
122
kwargs = {
114
123
"request" : request ,
@@ -143,17 +152,12 @@ def send_request(self, request: InjectionRequest):
143
152
:return the injection response received from the request
144
153
:rtype InjectionResponse
145
154
"""
146
- headers = {
147
- 'User-Agent' : self .__user_agent ,
148
- 'Content-Type' : 'application/json; charset=utf-8' ,
149
- 'Accept' : 'application/json' ,
150
- }
151
155
152
156
json_body = json .dumps (request .to_json ())
153
157
154
158
try :
155
159
connection = self .__get_connection ()
156
- connection .request ("POST" , self ._endpoint .url , json_body , headers )
160
+ connection .request ("POST" , self ._endpoint .url , json_body , self . _headers )
157
161
response = connection .getresponse ()
158
162
159
163
except Exception as e :
0 commit comments