Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

Commit e3e2b08

Browse files
author
Alon Katz
authored
feat(http): add API GW support (#362)
* Add support for api gateway of type HTTP * no message * no message * no message * no message * no message
1 parent 1df3f1e commit e3e2b08

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

epsagon/utils.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,23 @@ def update_http_headers(resource_data, response_headers):
7575
:param response_headers: response headers from HTTP request
7676
:return: update resource data dict
7777
"""
78-
for header_key, header_value in response_headers.items():
79-
if header_key.lower() == 'x-amzn-requestid':
80-
# This is a request to API Gateway
81-
if '.appsync-api.' not in resource_data['metadata']['url']:
82-
resource_data['type'] = 'api_gateway'
83-
resource_data['metadata']['request_trace_id'] = header_value
84-
break
78+
lowered_response_headers = \
79+
dict((k.lower(), v) for k, v in response_headers.items())
80+
81+
# 'x-amzn-requestid' is sent for type REST in api gateway
82+
# and 'apigw-requestid' is sent in type HTTP for backwards compatibility
83+
# we always try to get 'x-amzn-requestid' first
84+
request_id = \
85+
lowered_response_headers.get(
86+
'x-amzn-requestid',
87+
lowered_response_headers.get('apigw-requestid')
88+
)
89+
90+
if request_id:
91+
# This is a request to API Gateway
92+
if '.appsync-api.' not in resource_data['metadata']['url']:
93+
resource_data['type'] = 'api_gateway'
94+
resource_data['metadata']['request_trace_id'] = request_id
8595

8696
return resource_data
8797

0 commit comments

Comments
 (0)