From 4e66779b918b4493c1678a0fd665cbd0b7620a20 Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Mon, 18 Mar 2024 10:48:53 +0100 Subject: [PATCH] feat: add host header --- harp_apps/proxy/controllers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/harp_apps/proxy/controllers.py b/harp_apps/proxy/controllers.py index 9d420b89..b4d95481 100644 --- a/harp_apps/proxy/controllers.py +++ b/harp_apps/proxy/controllers.py @@ -1,7 +1,7 @@ from datetime import UTC, datetime from functools import cached_property from typing import Optional -from urllib.parse import urlencode, urljoin +from urllib.parse import urlencode, urljoin, urlparse import httpx from httpx import AsyncClient, codes @@ -40,6 +40,8 @@ def __init__(self, url, *, http_client: AsyncClient, dispatcher=None, name=None) self.name = name or self.name self._dispatcher = dispatcher or self._dispatcher + self.parsed_url = urlparse(self.url) + async def adispatch(self, event_id, event=None): """ Shortcut method to dispatch an event using the controller's dispatcher, if there is one. @@ -67,6 +69,7 @@ async def __call__(self, request: HttpRequest): tags[k[7:]] = v elif k not in ("host",): headers.append((k, v)) + headers.append(("host", self.parsed_url.netloc)) transaction = await self._create_transaction_from_request(request, tags=tags) await request.join()