Skip to content

[Rust Frontend] Add CORS support#45753

Open
tahsintunan wants to merge 1 commit into
vllm-project:mainfrom
tahsintunan:rust/cors
Open

[Rust Frontend] Add CORS support#45753
tahsintunan wants to merge 1 commit into
vllm-project:mainfrom
tahsintunan:rust/cors

Conversation

@tahsintunan

Copy link
Copy Markdown
Contributor

Summary

  • Adds CORS to the Rust frontend (tracking: [Roadmap] Rust Frontend Feature Parity #44280), matching the Python frontend's Starlette CORSMiddleware.
  • A tower_http::cors::CorsLayer is applied to every response with the same permissive defaults Python uses (allow_origins=["*"], methods/headers ["*"], credentials off), plus a small middleware that keeps non-CORS responses clean.

Notes

  • CorsLayer reproduces Starlette's browser behavior: * methods expand to an explicit list, allowed headers union the safelisted set, max-age is 600, Vary: Origin only emits when the origin is dynamic, and * + credentials reflects the request origin (avoids tower-http's wildcard+credentials panic).
  • A strip_cors_on_no_origin middleware strips CORS headers from requests without an Origin, keeping non-browser traffic (/health, plain curl) clean.
  • CORS sits inside auth in the layer stack, so 401s carry no CORS headers. Preflight OPTIONS bypasses auth and still gets headers.

Known divergences (all browser-invisible)

  • A rejected preflight returns 200 with disallowed headers absent, instead of Starlette's 400 "Disallowed CORS ...". The browser blocks the request either way (matching the 400 would mean reimplementing tower-http's internals).
  • A bare OPTIONS (no Access-Control-Request-Method) returns 200 instead of 405.

Signed-off-by: Tahsin Tunan <tahsintunan@gmail.com>
@mergify mergify Bot added the rust label Jun 16, 2026
@BugenZhao

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6c8d2e5ea0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread rust/src/cmd/src/cli.rs
Comment on lines +242 to +245
long,
default_missing_value = "true",
num_args = 0..=1
)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the Python --no-allow-credentials flag

For CLI invocations that include the Python-generated negative boolean form --no-allow-credentials (the Python arg builder uses BooleanOptionalAction for bool fields, and the old unsupported entry explicitly recognized this alias), this new supported clap arg only registers --allow-credentials, so the Rust frontend rejects a valid vLLM CORS flag instead of treating it as false. This matters for wrappers or config renderers that emit explicit negative bools; please add proper handling for the negative form when enabling this option.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows how the Rust frontend already handles implemented bool flags: negation is --allow-credentials false, not --no-allow-credentials. None of the existing implemented bool flags mirror Python's --no- form either — e.g. --enable-request-id-headers (which this is modeled on), --enable-prompt-tokens-details, --disable-log-stats all accept --flag true/false only, while Python generates a --no- variant for each via BooleanOptionalAction.

@mergify

mergify Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @tahsintunan.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants