Skip to content

Commit

Permalink
Merge pull request #86 from maciej-wichowski/fix-route_v8_headers_in_…
Browse files Browse the repository at this point in the history
…request

[FIX] Support passing headers in `route_v8`
  • Loading branch information
abdullahselek authored Oct 19, 2024
2 parents 90d43d0 + 2288049 commit 878aa65
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion herepy/routing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,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 @@ -492,6 +493,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 @@ -1257,3 +1257,20 @@ def test_route_v8_truck_parameter_deprecated(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")

0 comments on commit 878aa65

Please sign in to comment.