Requests without "Accept: text/event-stream" header are ignored
yaourt opened this issue · 2 comments
Hi !
First of all, thanks for this neat & useful library !
I'm seeing here :
that if the incoming request does not have the Accept: text/event-stream
header then the middleware is not processing it.
I am not sure if this request header is mandatory, here https://html.spec.whatwg.org/multipage/server-sent-events.html#the-eventsource-interface , in the paragaph
The EventSource(url, eventSourceInitDict) constructor, when invoked, must run these steps:
the item 10 is then:
User agents may set
Accept
/text/event-stream
in request's header list.
may not must ...
Could you consider having this behavior configurable / optional ?
What do you think ? Am I interpreting something wrong ?
Again, thanks for sharing this lib !
I believe your interpretation to be correct. In fact I think the statement below from different version of spec describes it the best.
For HTTP connections, the Accept header may be included; if included, it must contain only formats of event framing that are supported by the user agent (one of which must be text/event-stream).
So if Accept
requet header is present, it should contain text/event-stream
, but the Accept
request header doesn't have to be present.
I'll treat it as a low priority bug.
I'm sorry, I'm not able to run the test in my environment, so I cannot propose a PR ...
Following your comment, I would process the request:
- if the Accept header is there with "text/event-stream" value
- or if the Accept is not there
My proposed approach would then be to replace the current if block by the following one :
if ( ( context.Request.Headers.ContainsKey(Constants.ACCEPT_HTTP_HEADER)
&&
context.Request.Headers[Constants.ACCEPT_HTTP_HEADER] == Constants.SSE_CONTENT_TYPE )
||
! context.Request.Headers.ContainsKey(Constants.ACCEPT_HTTP_HEADER)
)