Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions plugins/nemo-agents/src/nemo_agents_plugin/api/v2/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import logging
import os
from typing import AsyncIterator
from urllib.parse import urljoin, urlparse
from urllib.parse import urljoin, urlparse, urlunparse

import httpx
from fastapi import APIRouter, Depends, HTTPException, Request
Expand Down Expand Up @@ -158,10 +158,14 @@ async def _proxy(
transfer encoding makes the original value invalid.
"""
endpoint_parsed = urlparse(endpoint)
target_url = urljoin(endpoint.rstrip("/") + "/", trailing_uri)
target_parsed = urlparse(target_url)
if target_parsed.scheme != endpoint_parsed.scheme or target_parsed.netloc != endpoint_parsed.netloc:
if not endpoint_parsed.scheme or not endpoint_parsed.netloc:
raise HTTPException(status_code=500, detail="Deployment endpoint is misconfigured.")
joined = urlparse(urljoin(endpoint.rstrip("/") + "/", trailing_uri))
if joined.scheme != endpoint_parsed.scheme or joined.netloc != endpoint_parsed.netloc:
raise HTTPException(status_code=400, detail="Invalid proxy target URI.")
target_url = urlunparse(
(endpoint_parsed.scheme, endpoint_parsed.netloc, joined.path, joined.params, joined.query, "")
)
if request.url.query:
target_url = f"{target_url}?{request.url.query}"

Expand Down
Loading