adamchel / rn-eventsource

An EventSource implementation built on top of React Native's low-level Networking API
41 stars 12 forks source link

Content type check is prone to error if additional params are added #25

Open yunusyuksel opened 1 year ago

yunusyuksel commented 1 year ago

That check to content type "text/event-stream" causes an error, if to content type additional params are added like "charset=utf-8". See here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type. we may check the substring of content type?

if ( responseHeaders && responseHeaders['content-type'] !== 'text/event-stream' ) { this.dispatchEvent({ type: 'error', data: 'unsupported MIME type in response: ' + responseHeaders['content-type'], }); return this.close(); } else if (!responseHeaders) { this.dispatchEvent({ type: 'error', data: 'no MIME type in response', }); return this.close(); }