Skip to content

Commit 2288049

Browse files
[FIX] Support passing headers in route_v8
1 parent a9a623f commit 2288049

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

herepy/routing_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ def __get(
4949
response_cls,
5050
manipulation_key: str = None,
5151
keys_for_manipulation: List = None,
52+
headers: Optional[Dict[str, str]] = None,
5253
):
5354
url = Utils.build_url(base_url, extra_params=data)
5455
if manipulation_key and keys_for_manipulation:
5556
for k in keys_for_manipulation:
5657
url = url.replace(k, manipulation_key)
57-
response = requests.get(url, timeout=self._timeout)
58+
response = requests.get(url, timeout=self._timeout, headers=headers)
5859
json_data = json.loads(response.content.decode("utf8"))
5960
if response.status_code == requests.codes.OK:
6061
return response_cls.new_from_jsondict(json_data)
@@ -480,6 +481,7 @@ def route_v8(
480481
RoutingResponseV8,
481482
manipulation_key="via",
482483
keys_for_manipulation=via_keys,
484+
headers=headers
483485
)
484486
return response
485487

tests/test_routing_api.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,3 +1234,20 @@ def test_route_v8_url_parameters_multiple(self):
12341234
destination=[41.9043, -87.9216],
12351235
truck={"height": ["15000"], "width": ["3000"]}
12361236
)
1237+
1238+
@responses.activate
1239+
def test_route_v8_headers_in_request(self):
1240+
resp = responses.add(
1241+
responses.GET,
1242+
"https://router.hereapi.com/v8/routes",
1243+
"{}",
1244+
status=200,
1245+
)
1246+
self._api.route_v8(
1247+
transport_mode=herepy.RoutingTransportMode.truck,
1248+
origin=[41.9798, -87.8801],
1249+
destination=[41.9043, -87.9216],
1250+
headers={"X-BIP": "BOP"},
1251+
)
1252+
original_request = resp.calls[0].request
1253+
self.assertEqual(original_request.headers.get("X-BIP"), "BOP")

0 commit comments

Comments
 (0)