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

Commit

Permalink
feat(http): add API GW support (#362)
Browse files Browse the repository at this point in the history
* Add support for api gateway of type HTTP

* no message

* no message

* no message

* no message

* no message
  • Loading branch information
Alon-Katz authored Jun 28, 2021
1 parent 1df3f1e commit e3e2b08
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions epsagon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,23 @@ def update_http_headers(resource_data, response_headers):
:param response_headers: response headers from HTTP request
:return: update resource data dict
"""
for header_key, header_value in response_headers.items():
if header_key.lower() == 'x-amzn-requestid':
# This is a request to API Gateway
if '.appsync-api.' not in resource_data['metadata']['url']:
resource_data['type'] = 'api_gateway'
resource_data['metadata']['request_trace_id'] = header_value
break
lowered_response_headers = \
dict((k.lower(), v) for k, v in response_headers.items())

# 'x-amzn-requestid' is sent for type REST in api gateway
# and 'apigw-requestid' is sent in type HTTP for backwards compatibility
# we always try to get 'x-amzn-requestid' first
request_id = \
lowered_response_headers.get(
'x-amzn-requestid',
lowered_response_headers.get('apigw-requestid')
)

if request_id:
# This is a request to API Gateway
if '.appsync-api.' not in resource_data['metadata']['url']:
resource_data['type'] = 'api_gateway'
resource_data['metadata']['request_trace_id'] = request_id

return resource_data

Expand Down

0 comments on commit e3e2b08

Please sign in to comment.