Skip to content

Commit

Permalink
Pass additional HTTP headers into Endpoint.prepare_request() (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
iansrobinson authored Sep 8, 2020
1 parent d2b6186 commit 5fb4f7f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions neptune-python-utils/neptune_python_utils/bulkload.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ def __load(self, loader_endpoint, data):

json_string = json.dumps(data)
json_bytes = json_string.encode('utf8')
request_parameters = loader_endpoint.prepare_request('POST', json_string)
request_parameters.headers['Content-Type'] = 'application/json'
request_parameters = loader_endpoint.prepare_request('POST', json_string, headers={'Content-Type':'application/json'})
req = urllib.request.Request(request_parameters.uri, data=json_bytes, headers=request_parameters.headers)
try:
response = urllib.request.urlopen(req)
Expand Down
8 changes: 6 additions & 2 deletions neptune-python-utils/neptune_python_utils/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def __init__(self, lazy_headers):

def get_all(self) -> Iterable[Tuple[str, str]]:
return self.lazy_headers().items()

def items(self):
return self.lazy_headers().items()


class RequestParameters:
Expand Down Expand Up @@ -110,7 +113,7 @@ def _new_credentials(self):
def value(self):
return '{}://{}:{}/{}'.format(self.protocol, self.neptune_endpoint, self.neptune_port, self.suffix)

def prepare_request(self, method='GET', payload='', querystring={}):
def prepare_request(self, method='GET', payload='', querystring={}, headers={}):

service = 'neptune-db'
algorithm = 'AWS4-HMAC-SHA256'
Expand Down Expand Up @@ -159,7 +162,8 @@ def get_headers():
credential_scope,
signed_headers,
signature)
headers = {'x-amz-date':amzdate, 'Authorization':authorization_header}
headers['x-amz-date'] = amzdate
headers['Authorization'] = authorization_header
if session_token:
headers['x-amz-security-token'] = session_token

Expand Down

0 comments on commit 5fb4f7f

Please sign in to comment.