proxyToUpstream: add redirect with trailing slash to upstream endpoint (#322)
This adds a redirect to the upstream endpoint so it always ends with a trailing /. Fixes #321
This commit is contained in:
@@ -419,6 +419,24 @@ func (pm *ProxyManager) proxyToUpstream(c *gin.Context) {
|
|||||||
modelName = real
|
modelName = real
|
||||||
remainingPath = "/" + strings.Join(parts[i+1:], "/")
|
remainingPath = "/" + strings.Join(parts[i+1:], "/")
|
||||||
modelFound = true
|
modelFound = true
|
||||||
|
|
||||||
|
// Check if this is exactly a model name with no additional path
|
||||||
|
// and doesn't end with a trailing slash
|
||||||
|
if remainingPath == "/" && !strings.HasSuffix(upstreamPath, "/") {
|
||||||
|
// Build new URL with query parameters preserved
|
||||||
|
newPath := "/upstream/" + searchModelName + "/"
|
||||||
|
if c.Request.URL.RawQuery != "" {
|
||||||
|
newPath += "?" + c.Request.URL.RawQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use 308 for non-GET/HEAD requests to preserve method
|
||||||
|
if c.Request.Method == http.MethodGet || c.Request.Method == http.MethodHead {
|
||||||
|
c.Redirect(http.StatusMovedPermanently, newPath)
|
||||||
|
} else {
|
||||||
|
c.Redirect(http.StatusPermanentRedirect, newPath)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -438,6 +456,7 @@ func (pm *ProxyManager) proxyToUpstream(c *gin.Context) {
|
|||||||
c.Request.URL.Path = remainingPath
|
c.Request.URL.Path = remainingPath
|
||||||
processGroup.ProxyRequest(realModelName, c.Writer, c.Request)
|
processGroup.ProxyRequest(realModelName, c.Writer, c.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pm *ProxyManager) proxyOAIHandler(c *gin.Context) {
|
func (pm *ProxyManager) proxyOAIHandler(c *gin.Context) {
|
||||||
bodyBytes, err := io.ReadAll(c.Request.Body)
|
bodyBytes, err := io.ReadAll(c.Request.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user