Skip to content

Add HTTP method constraint for categorizing SSE requests - #470

Open
dylan-mccormick wants to merge 1 commit into
ESP32Async:mainfrom
dylan-mccormick:sse-method-fix
Open

Add HTTP method constraint for categorizing SSE requests#470
dylan-mccormick wants to merge 1 commit into
ESP32Async:mainfrom
dylan-mccormick:sse-method-fix

Conversation

@dylan-mccormick

Copy link
Copy Markdown

Problem

In ESPAsyncWebServer.h:586, the isSSE method is true only if the HTTP method is a GET request and the _reqconntype is RCT_EVENT.

bool isSSE() const {
  return _method == AsyncWebRequestMethod::HTTP_GET && isExpectedRequestedConnType(RCT_EVENT);
}

However, WebRequest.cpp:671's header parsing matches SSE to Accept: text/event-stream, regardless of the HTTP method used. If a request uses the POST method while still including text/event-stream in the Accept header, it will be classified as an RCT_EVENT, but fails to match isSSE since it is not a GET request, causing it to miss any HTTP handlers for that endpoint

Example

A POST request to /mcp with the header Accept: application/json, text/event-stream will end up being routed by the not found handler, because _reqconntype gets set to RCT_EVENT from the Accept header, regardless of HTTP method. But, isHTTP only accepts RCT_DEFAULT and RCT_HTTP, and isSSE requires GET, so the request satisfies neither.

server.on("/mcp", HTTP_POST, [](AsyncWebServerRequest* r) {
    r->send(200, "text/plain", "OK");
});

Fix

Added an additional condition to the header-parsing logic in WebRequest.cpp, requiring that the request method must be GET in addition to the presence of Accept: text/event-stream.

Copilot AI review requested due to automatic review settings July 30, 2026 00:28

Copilot AI 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.

🟡 Not ready to approve

The updated SSE detection still allows _reqconntype to be overwritten based on header order (e.g., potentially overriding a WebSocket upgrade), which should be guarded to avoid misclassification.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR tightens SSE (Server-Sent Events) request classification during header parsing so that Accept: text/event-stream only marks a request as RCT_EVENT when the HTTP method is GET, aligning header parsing behavior with AsyncWebServerRequest::isSSE() and preventing POST requests from being misrouted.

Changes:

  • Require HTTP_GET in Accept: text/event-stream detection before setting _reqconntype = RCT_EVENT.
File summaries
File Description
src/WebRequest.cpp Adds an HTTP method constraint to SSE detection in request header parsing.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Low

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread src/WebRequest.cpp
Comment on lines +671 to 674
if (substr != NULL && _method == AsyncWebRequestMethod::HTTP_GET) {
// WebEvent request can be uniquely identified by header: [Accept: text/event-stream]
_reqconntype = RCT_EVENT;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants