Skip to content

Commit ec7e7c2

Browse files
suger-mPangjiping
authored andcommitted
fix(server): use internal endpoint resolution for proxy route
1 parent cbd22e6 commit ec7e7c2

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

server/src/api/lifecycle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ async def proxy_sandbox_endpoint_request(request: Request, sandbox_id: str, port
428428
and asynchronously proxies the request to it.
429429
"""
430430

431-
endpoint = sandbox_service.get_endpoint(sandbox_id, port)
431+
endpoint = sandbox_service.get_endpoint(sandbox_id, port, resolve_internal=True)
432432

433433
target_host = endpoint.endpoint
434434
query_string = request.url.query

server/tests/test_routes_proxy.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ def test_proxy_forwards_filtered_headers_and_query(
6161
) -> None:
6262
class StubService:
6363
@staticmethod
64-
def get_endpoint(sandbox_id: str, port: int) -> Endpoint:
64+
def get_endpoint(sandbox_id: str, port: int, resolve_internal: bool = False) -> Endpoint:
6565
assert sandbox_id == "sbx-123"
6666
assert port == 44772
67+
assert resolve_internal is True
6768
return Endpoint(endpoint="10.57.1.91:40109")
6869

6970
monkeypatch.setattr(lifecycle, "sandbox_service", StubService())
@@ -116,7 +117,7 @@ def test_proxy_rejects_websocket_upgrade(
116117
) -> None:
117118
class StubService:
118119
@staticmethod
119-
def get_endpoint(sandbox_id: str, port: int) -> Endpoint:
120+
def get_endpoint(sandbox_id: str, port: int, resolve_internal: bool = False) -> Endpoint:
120121
return Endpoint(endpoint="10.57.1.91:40109")
121122

122123
monkeypatch.setattr(lifecycle, "sandbox_service", StubService())
@@ -138,7 +139,7 @@ def test_proxy_rejects_websocket_upgrade_for_post_and_mixed_case_header(
138139
) -> None:
139140
class StubService:
140141
@staticmethod
141-
def get_endpoint(sandbox_id: str, port: int) -> Endpoint:
142+
def get_endpoint(sandbox_id: str, port: int, resolve_internal: bool = False) -> Endpoint:
142143
return Endpoint(endpoint="10.57.1.91:40109")
143144

144145
monkeypatch.setattr(lifecycle, "sandbox_service", StubService())
@@ -161,7 +162,7 @@ def test_proxy_maps_connect_error_to_502(
161162
) -> None:
162163
class StubService:
163164
@staticmethod
164-
def get_endpoint(sandbox_id: str, port: int) -> Endpoint:
165+
def get_endpoint(sandbox_id: str, port: int, resolve_internal: bool = False) -> Endpoint:
165166
return Endpoint(endpoint="10.57.1.91:40109")
166167

167168
monkeypatch.setattr(lifecycle, "sandbox_service", StubService())
@@ -185,7 +186,7 @@ def test_proxy_maps_unexpected_error_to_500(
185186
) -> None:
186187
class StubService:
187188
@staticmethod
188-
def get_endpoint(sandbox_id: str, port: int) -> Endpoint:
189+
def get_endpoint(sandbox_id: str, port: int, resolve_internal: bool = False) -> Endpoint:
189190
return Endpoint(endpoint="10.57.1.91:40109")
190191

191192
monkeypatch.setattr(lifecycle, "sandbox_service", StubService())

0 commit comments

Comments
 (0)