You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@casbin.apache.org by "BeiBaiNian (via GitHub)" <gi...@apache.org> on 2026/08/16 15:14:56 UTC
[PR] fix: normalize the /v1 prefix when building upstream urls [casbin-gateway]
BeiBaiNian opened a new pull request, #198:
URL: https://github.com/apache/casbin-gateway/pull/198
# Why
A channel whose base URL carries the standard /v1 prefix (the exact form suggested by the web UI presets and most upstream docs, e.g. https://api.openai.com/v1) was broken: controllers/proxy.go unconditionally appended /v1/chat/completions to the base URL, producing a doubled path like https://api.openai.com/v1/v1/chat/completions that the upstream answers with 404. The openai connectivity probe had the same flaw (/v1/v1/models).
# What changed
- object/channel.go: added BuildOpenAiUrl(baseUrl, endpoint), which normalizes the base URL before appending the endpoint. Bare hosts, /v1-suffixed base URLs (with or without a trailing slash) and subpaths ending in /v1 are all accepted; the endpoint is never doubled. The openai connectivity probe now builds its /models URL through this function.
- controllers/proxy.go: the upstream chat completions URL is now built with object.BuildOpenAiUrl(channel.BaseUrl, "/chat/completions") instead of string concatenation.
- Tests: table-driven unit tests covering seven base URL shapes (object/channel_test.go) and an end-to-end forwarding test with a /v1-prefixed base URL (controllers/proxy_test.go).
# Verification
- go build ./... passes.
- go test ./object/ -run TestBuildOpenAiUrl -v passes (7 cases).
- go test ./controllers/ -run TestForwardToChannel -v passes, including the new TestForwardToChannelWithV1BaseUrl.
- Live end-to-end test against a real upstream: a channel with base URL https://api.openai.com/v1 passes Test Connection, and POST /v1/chat/completions returns a normal completion response instead of the previous upstream 404.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For additional commands, e-mail: commits-help@casbin.apache.org
Re: [PR] fix: normalize the /v1 prefix when building upstream urls [casbin-gateway]
Posted by "hsluoyz (via GitHub)" <gi...@apache.org>.
hsluoyz closed pull request #198: fix: normalize the /v1 prefix when building upstream urls
URL: https://github.com/apache/casbin-gateway/pull/198
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For additional commands, e-mail: commits-help@casbin.apache.org
Re: [PR] fix: normalize the /v1 prefix when building upstream urls [casbin-gateway]
Posted by "hsluoyz (via GitHub)" <gi...@apache.org>.
hsluoyz commented on PR #198:
URL: https://github.com/apache/casbin-gateway/pull/198#issuecomment-5308237271
replaced by: https://github.com/apache/casbin-gateway/commit/9152178969ab32f70ab29f2e091798c5e549ba50
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For additional commands, e-mail: commits-help@casbin.apache.org