This is an automated email from the ASF dual-hosted git repository.
hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-gateway.git
The following commit(s) were added to refs/heads/master by this push:
new fbfb9c7 fix(proxy): keep the client's query string on the upstream URL
fbfb9c7 is described below
commit fbfb9c732da88c80cef74bb7034e19dc52e13548
Author: Yang Luo <[email protected]>
AuthorDate: Sat Aug 22 17:25:42 2026 +0800
fix(proxy): keep the client's query string on the upstream URL
---
controllers/proxy.go | 1 +
object/channel.go | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/controllers/proxy.go b/controllers/proxy.go
index 1a9a9c1..0c6e864 100644
--- a/controllers/proxy.go
+++ b/controllers/proxy.go
@@ -319,6 +319,7 @@ func (c *ApiController) forwardToChannel(channel
*object.Channel, route *proxyRo
object.ReportChannelFailure(channel.GetId(), err.Error())
return http.StatusBadGateway, err.Error(), false
}
+ upstreamUrl = object.AppendQuery(upstreamUrl,
c.Ctx.Request.URL.RawQuery)
// The context is cancelled when this function returns, which happens
only
// after the response body has been relayed to the client.
diff --git a/object/channel.go b/object/channel.go
index fcec6eb..db45d31 100644
--- a/object/channel.go
+++ b/object/channel.go
@@ -380,6 +380,27 @@ func BuildChannelUrl(baseUrl string, protocol string,
endpoint string) (string,
return BuildOpenAiUrl(baseUrl, endpoint)
}
+// AppendQuery puts the query of the client request back on an upstream URL.
+// The query selects a variant of the endpoint — the Anthropic clients ask for
+// the beta one with "?beta=true" — so dropping it would forward a different
+// request than the one that was made. A base URL carrying a query of its own
+// keeps it, with the client's appended.
+func AppendQuery(rawUrl string, rawQuery string) string {
+ if rawQuery == "" {
+ return rawUrl
+ }
+
+ u, err := url.Parse(rawUrl)
+ if err != nil {
+ return rawUrl
+ }
+ if u.RawQuery != "" {
+ rawQuery = u.RawQuery + "&" + rawQuery
+ }
+ u.RawQuery = rawQuery
+ return u.String()
+}
+
// SetChannelAuth puts the channel's credentials on an upstream request, in the
// header the channel's protocol authenticates with.
func SetChannelAuth(header http.Header, channel *Channel) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]