-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #583 from msqd/portless_endpoints
💬 [feat/0.8] portless endpoints (endpoints that does not listen to a port but are only there to handle subrequests)
- Loading branch information
Showing
13 changed files
with
178 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
Unreleased | ||
========== | ||
|
||
Added | ||
::::::: | ||
|
||
* Proxy: it is now possible to add not exposed endpoints in the proxy configuration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from httpx import AsyncClient | ||
|
||
from harp.controllers import ProxyControllerResolver | ||
from harp.http import HttpRequest | ||
from harp_apps.proxy.controllers import HttpProxyController | ||
from harp_apps.proxy.settings.endpoint import Endpoint | ||
|
||
|
||
def test_add(): | ||
http_client = AsyncClient() | ||
endpoint = Endpoint.from_kwargs(settings={"name": "test-endpoint", "port": 8080, "url": "http://example.com/"}) | ||
resolver = ProxyControllerResolver() | ||
|
||
resolver.add(endpoint, http_client=http_client, ControllerType=HttpProxyController) | ||
assert resolver.endpoints["test-endpoint"] == endpoint | ||
assert resolver.ports == (8080,) | ||
|
||
|
||
async def test_resolve(): | ||
http_client = AsyncClient() | ||
endpoint = Endpoint.from_kwargs(settings={"name": "test-endpoint", "port": 8080, "url": "http://example.com/"}) | ||
resolver = ProxyControllerResolver() | ||
resolver.add(endpoint, http_client=http_client, ControllerType=HttpProxyController) | ||
|
||
request = HttpRequest(server_port=8080) | ||
controller = await resolver.resolve(request) | ||
assert isinstance(controller, HttpProxyController) | ||
assert controller.name == "test-endpoint" | ||
|
||
request = HttpRequest(server_port=8081) | ||
controller = await resolver.resolve(request) | ||
assert controller is resolver.default_controller | ||
|
||
|
||
def test_resolve_from_endpoint_name(): | ||
http_client = AsyncClient() | ||
endpoint = Endpoint.from_kwargs(settings={"name": "test-endpoint", "port": 8080, "url": "http://example.com/"}) | ||
resolver = ProxyControllerResolver() | ||
resolver.add(endpoint, http_client=http_client, ControllerType=HttpProxyController) | ||
|
||
controller = resolver.resolve_from_endpoint_name("test-endpoint") | ||
assert isinstance(controller, HttpProxyController) | ||
assert controller.name == "test-endpoint" | ||
|
||
controller = resolver.resolve_from_endpoint_name("non-existent") | ||
assert controller is resolver.default_controller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ proxy.endpoints: | |
- port: 4002 | ||
name: httpbin3 | ||
url: http://httpbin.org | ||
- name: httpbin4 | ||
url: http://httpbin.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.