99from ..version import __version__
1010from ..proxy import Proxy
1111
12+ from .stringextension import StringExtension
1213from .httpendpoint import HttpEndpoint
1314from .injectionresponseparser import InjectionResponseParser
1415from .serialization .injectionrequest import InjectionRequest
@@ -28,7 +29,7 @@ class HttpRequestMethod(Enum):
2829 PUT = 2
2930 DELETE = 3
3031
31- def __init__ (self , method : HttpRequestMethod , endpoint : HttpEndpoint , timeout : int ):
32+ def __init__ (self , method : HttpRequestMethod , endpoint : HttpEndpoint , timeout : int , authentication : str ):
3233 """
3334 Creates a new instance of the HTTP Request class
3435 :param method: the HTTP request method
@@ -40,6 +41,14 @@ def __init__(self, method: HttpRequestMethod, endpoint: HttpEndpoint, timeout: i
4041 self ._endpoint = endpoint
4142 self ._http_proxy = None
4243 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
4352
4453 @property
4554 def __user_agent (self ):
@@ -108,7 +117,7 @@ def send_async_request(self, request: InjectionRequest, on_success_callback, on_
108117 """
109118
110119 try :
111-
120+ print ( request )
112121 th = threading .Thread (target = self .__queue_request ,
113122 kwargs = {
114123 "request" : request ,
@@ -143,17 +152,12 @@ def send_request(self, request: InjectionRequest):
143152 :return the injection response received from the request
144153 :rtype InjectionResponse
145154 """
146- headers = {
147- 'User-Agent' : self .__user_agent ,
148- 'Content-Type' : 'application/json; charset=utf-8' ,
149- 'Accept' : 'application/json' ,
150- }
151155
152156 json_body = json .dumps (request .to_json ())
153157
154158 try :
155159 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 )
157161 response = connection .getresponse ()
158162
159163 except Exception as e :
0 commit comments