-
-
Notifications
You must be signed in to change notification settings - Fork 42
feat: CORS implementation #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
45d9ec0
initial config for CORS
thushan 2f7db1e
WIP: add the cORS middleware and map to handler.
thushan 61e430c
wire the handler and add tests
thushan 1c1341b
doc updates
thushan 7429a9b
update docs and update readme.
thushan 3e2f7d7
avoid empty allowed_oriiginss when CORS is enabled
thushan 2000207
add cors to allowed list and fix
thushan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package middleware | ||
|
|
||
| import ( | ||
| "github.com/rs/cors" | ||
| "github.com/thushan/olla/internal/config" | ||
| "github.com/thushan/olla/internal/core/constants" | ||
| ) | ||
|
|
||
| // DefaultCORSExposedHeaders is the set of X-Olla-* response headers exposed to | ||
| // browser clients when the caller has not configured explicit ExposedHeaders. | ||
| // | ||
| // By default browsers block non-simple response headers from cross-origin reads. | ||
| // Olla's routing, model, and sticky-session metadata all live in X-Olla-* headers, | ||
| // so browser clients (OpenWebUI, custom dashboards) cannot inspect them without | ||
| // this exposure list. We expose the full set rather than a subset to avoid | ||
| // surprising omissions when new headers are added to the proxy output. | ||
| var DefaultCORSExposedHeaders = []string{ | ||
| constants.HeaderXOllaRequestID, | ||
| constants.HeaderXOllaEndpoint, | ||
| constants.HeaderXOllaBackendType, | ||
| constants.HeaderXOllaModel, | ||
| constants.HeaderXOllaResponseTime, | ||
| constants.HeaderXOllaRoutingStrategy, | ||
| constants.HeaderXOllaRoutingDecision, | ||
| constants.HeaderXOllaRoutingReason, | ||
| constants.HeaderXOllaMode, | ||
| constants.HeaderXOllaStickySession, | ||
| constants.HeaderXOllaStickyKeySource, | ||
| constants.HeaderXOllaSessionID, | ||
| } | ||
|
|
||
| // NewCORS builds an rs/cors handler from Olla's CORS config. It is only constructed | ||
| // when CORS is enabled (the caller gates on cfg.Enabled). When ExposedHeaders is empty | ||
| // we expose the full X-Olla-* response header set so browser clients can read Olla's | ||
| // routing/model metadata, which they otherwise cannot access cross-origin. | ||
| func NewCORS(cfg config.CorsConfig) *cors.Cors { | ||
| exposed := cfg.ExposedHeaders | ||
| if len(exposed) == 0 { | ||
| exposed = DefaultCORSExposedHeaders | ||
| } | ||
|
|
||
| return cors.New(cors.Options{ | ||
| AllowedOrigins: cfg.AllowedOrigins, | ||
| AllowedMethods: cfg.AllowedMethods, | ||
| AllowedHeaders: cfg.AllowedHeaders, | ||
| ExposedHeaders: exposed, | ||
| AllowCredentials: cfg.AllowCredentials, | ||
| MaxAge: cfg.MaxAge, | ||
| }) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use indented code block style to satisfy markdownlint (MD046).
This fenced YAML block breaks the configured code-block-style rule and may keep docs lint noisy or failing. Convert this block to indented style to match the repository convention.
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 150-150: Code block style
Expected: indented; Actual: fenced
(MD046, code-block-style)
🤖 Prompt for AI Agents
Source: Linters/SAST tools