@@ -72,6 +72,34 @@ async def shutdown(self):
7272 async def process_task (self , task ):
7373 logger .info (f'new webtask received: { task .request .method } { task .request .url } ' )
7474 headers = copy .copy (task .request .headers )
75+ headers .update (self .get_internal_headers (task ))
76+ message = None
77+ try :
78+ async with httpx .AsyncClient (
79+ app = self .handler .app , base_url = 'http://localhost' ,
80+ ) as client :
81+ body = (
82+ base64 .decodebytes (task .request .content .encode ('utf-8' ))
83+ if task .request .content else b''
84+ )
85+ response = await client .request (
86+ task .request .method ,
87+ task .request .url ,
88+ headers = headers ,
89+ content = body ,
90+ )
91+
92+ message = self .build_response (
93+ task , response .status_code , response .headers , response .content ,
94+ )
95+ except Exception as e :
96+ message = self .build_response (
97+ task , 500 , {}, str (e ).encode ('utf-8' ),
98+ )
99+ await self .send (message )
100+
101+ def get_internal_headers (self , task ):
102+ headers = {}
75103 headers ['X-Connect-Api-Gateway-Url' ] = self .config .get_api_url ()
76104 headers ['X-Connect-User-Agent' ] = self .config .get_user_agent ()['User-Agent' ]
77105 headers ['X-Connect-Extension-Id' ] = self .config .service_id
@@ -83,26 +111,29 @@ async def process_task(self, task):
83111 if task .options .installation_id :
84112 headers ['X-Connect-Installation-Id' ] = task .options .installation_id
85113
114+ if task .options .connect_correlation_id :
115+ headers ['X-Connect-Correlation-Id' ] = task .options .connect_correlation_id
116+
117+ if task .options .user_id :
118+ headers ['X-Connect-User-Id' ] = task .options .user_id
119+
120+ if task .options .account_id :
121+ headers ['X-Connect-Account-Id' ] = task .options .account_id
122+
123+ if task .options .account_role :
124+ headers ['X-Connect-Account-Role' ] = task .options .account_role
125+
126+ if task .options .call_type :
127+ headers ['X-Connect-Call-Type' ] = task .options .call_type
128+
129+ if task .options .call_source :
130+ headers ['X-Connect-Call-Source' ] = task .options .call_source
131+
86132 if self .config .logging_api_key is not None :
87133 headers ['X-Connect-Logging-Api-Key' ] = self .config .logging_api_key
88134 headers ['X-Connect-Logging-Metadata' ] = json .dumps (self .config .metadata )
89135
90- async with httpx .AsyncClient (app = self .handler .app , base_url = 'http://localhost' ) as client :
91- body = (
92- base64 .decodebytes (task .request .content .encode ('utf-8' ))
93- if task .request .content else b''
94- )
95- response = await client .request (
96- task .request .method ,
97- task .request .url ,
98- headers = headers ,
99- content = body ,
100- )
101-
102- message = self .build_response (
103- task , response .status_code , response .headers , response .content ,
104- )
105- await self .send (message )
136+ return headers
106137
107138 def build_response (self , task , status , headers , body ):
108139 log = logger .info if status < 500 else logger .error
0 commit comments