Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Support passing headers in route_v8 #86

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion herepy/routing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ def __get(
response_cls,
manipulation_key: str = None,
keys_for_manipulation: List = None,
headers: Optional[Dict[str, str]] = None,
):
url = Utils.build_url(base_url, extra_params=data)
if manipulation_key and keys_for_manipulation:
for k in keys_for_manipulation:
url = url.replace(k, manipulation_key)
response = requests.get(url, timeout=self._timeout)
response = requests.get(url, timeout=self._timeout, headers=headers)
json_data = json.loads(response.content.decode("utf8"))
if response.status_code == requests.codes.OK:
return response_cls.new_from_jsondict(json_data)
Expand Down Expand Up @@ -480,6 +481,7 @@ def route_v8(
RoutingResponseV8,
manipulation_key="via",
keys_for_manipulation=via_keys,
headers=headers
)
return response

Expand Down
17 changes: 17 additions & 0 deletions tests/test_routing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1234,3 +1234,20 @@ def test_route_v8_url_parameters_multiple(self):
destination=[41.9043, -87.9216],
truck={"height": ["15000"], "width": ["3000"]}
)

@responses.activate
def test_route_v8_headers_in_request(self):
resp = responses.add(
responses.GET,
"https://router.hereapi.com/v8/routes",
"{}",
status=200,
)
self._api.route_v8(
transport_mode=herepy.RoutingTransportMode.truck,
origin=[41.9798, -87.8801],
destination=[41.9043, -87.9216],
headers={"X-BIP": "BOP"},
)
original_request = resp.calls[0].request
self.assertEqual(original_request.headers.get("X-BIP"), "BOP")
Loading