Add HTTP method constraint for categorizing SSE requests - #470
Add HTTP method constraint for categorizing SSE requests#470dylan-mccormick wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟡 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_GETinAccept: text/event-streamdetection 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.
| if (substr != NULL && _method == AsyncWebRequestMethod::HTTP_GET) { | ||
| // WebEvent request can be uniquely identified by header: [Accept: text/event-stream] | ||
| _reqconntype = RCT_EVENT; | ||
| } |
Problem
In
ESPAsyncWebServer.h:586, theisSSEmethod is true only if the HTTP method is aGETrequest and the_reqconntypeisRCT_EVENT.However,
WebRequest.cpp:671's header parsing matches SSE toAccept: text/event-stream, regardless of the HTTP method used. If a request uses thePOSTmethod while still includingtext/event-streamin the Accept header, it will be classified as anRCT_EVENT, but fails to matchisSSEsince it is not aGETrequest, causing it to miss any HTTP handlers for that endpointExample
A
POSTrequest to/mcpwith the headerAccept: application/json, text/event-streamwill end up being routed by the not found handler, because_reqconntypegets set toRCT_EVENTfrom theAcceptheader, regardless of HTTP method. But,isHTTPonly acceptsRCT_DEFAULTandRCT_HTTP, andisSSErequiresGET, so the request satisfies neither.Fix
Added an additional condition to the header-parsing logic in
WebRequest.cpp, requiring that the request method must beGETin addition to the presence ofAccept: text/event-stream.