[PR #321] [CLOSED] serve: add CORS preflight (OPTIONS), reverse-proxy header support, and X-Accel-Buffering for SSE #2575

Closed
opened 2026-11-04 02:01:28 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/321
Author: @BlitzenCats
Created: 10/1/2026
Status: ❌ Closed

Base: main ← Head: feat/reverse-proxy-cors


📝 Commits (1)

  • 613feea serve: add CORS preflight (OPTIONS), reverse-proxy header support, and X-Accel-Buffering for SSE

📊 Changes

2 files changed (+42 additions, -3 deletions)

View changed files

📝 serve/server.py (+20 -3)
📝 serve/test_server.py (+22 -0)

📄 Description

Summary

This PR adds support for web-based API clients (CORS) and reverse proxies / tunnels (such as Cloudflare Tunnel, Tailscale Funnel, and Nginx) when remotely serving Strata or connecting third-party web frontends.

Key Changes

  1. CORS & Preflight (\OPTIONS\ 204 No Content):

    • Implements \do_OPTIONS\ returning \204 No Content\ with \Access-Control-Allow-Origin: *, \Access-Control-Allow-Methods: GET, POST, OPTIONS, and \Access-Control-Allow-Headers: *.
    • Without this, browser-based clients (such as Open WebUI, LibreChat, Chatbox, or browser extensions) making CORS preflight checks received \501 Unsupported method ('OPTIONS').
    • Adds standard CORS headers to JSON responses.
  2. Reverse Proxy Origin Validation:

    • Updates _own_page\ in \serve/server.py\ to inspect \X-Forwarded-Host\ and recognize proxy headers (\CF-Ray, \CF-Connecting-IP, \X-Forwarded-For).
    • Reverse proxies typically rewrite \Host: 127.0.0.1:8080\ while retaining \Origin: https://. Previously, this mismatch caused _own_page\ to trigger \403 Forbidden\ on settings and MCP tools when accessing Strata's web UI remotely through a tunnel.
  3. SSE Stream Buffering (\X-Accel-Buffering: no):

    • Adds \X-Accel-Buffering: no\ to _sse\ response headers to instruct edge/reverse proxies (Cloudflare, Nginx) not to buffer tokens, ensuring real-time streaming over Server-Sent Events.
  4. Unit Tests:

    • Added tests in \serve/test_server.py\ covering CORS preflights, response headers, and reverse-proxy forwarded origin handling (all 80+ server unit tests pass).

Authored by @BlitzenCats & Gemini


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/321 **Author:** [@BlitzenCats](https://github.com/BlitzenCats) **Created:** 10/1/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/reverse-proxy-cors` --- ### 📝 Commits (1) - [`613feea`](https://github.com/Niko1221/Strata/commit/613feea77da6468b75387571eddfe9ee44dda1f9) serve: add CORS preflight (OPTIONS), reverse-proxy header support, and X-Accel-Buffering for SSE ### 📊 Changes **2 files changed** (+42 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+20 -3) 📝 `serve/test_server.py` (+22 -0) </details> ### 📄 Description ### Summary This PR adds support for web-based API clients (CORS) and reverse proxies / tunnels (such as Cloudflare Tunnel, Tailscale Funnel, and Nginx) when remotely serving Strata or connecting third-party web frontends. ### Key Changes 1. **CORS & Preflight (\OPTIONS\ 204 No Content)**: - Implements \do_OPTIONS\ returning \204 No Content\ with \Access-Control-Allow-Origin: *\, \Access-Control-Allow-Methods: GET, POST, OPTIONS\, and \Access-Control-Allow-Headers: *\. - Without this, browser-based clients (such as Open WebUI, LibreChat, Chatbox, or browser extensions) making CORS preflight checks received \501 Unsupported method ('OPTIONS')\. - Adds standard CORS headers to JSON responses. 2. **Reverse Proxy Origin Validation**: - Updates \_own_page\ in \serve/server.py\ to inspect \X-Forwarded-Host\ and recognize proxy headers (\CF-Ray\, \CF-Connecting-IP\, \X-Forwarded-For\). - Reverse proxies typically rewrite \Host: 127.0.0.1:8080\ while retaining \Origin: https://<external-domain>\. Previously, this mismatch caused \_own_page\ to trigger \403 Forbidden\ on settings and MCP tools when accessing Strata's web UI remotely through a tunnel. 3. **SSE Stream Buffering (\X-Accel-Buffering: no\)**: - Adds \X-Accel-Buffering: no\ to \_sse\ response headers to instruct edge/reverse proxies (Cloudflare, Nginx) not to buffer tokens, ensuring real-time streaming over Server-Sent Events. 4. **Unit Tests**: - Added tests in \serve/test_server.py\ covering CORS preflights, response headers, and reverse-proxy forwarded origin handling (all 80+ server unit tests pass). --- *Authored by @BlitzenCats & Gemini* --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:01:28 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2575
No description provided.