Skip to content
This repository was archived by the owner on Apr 15, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions EventSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var EventSource = function (url, options) {

// NOTE: IE7 and upwards support
var xhr = new XMLHttpRequest();
xhr.open('GET', eventsource.URL, true);
xhr.open(eventsource.OPTIONS.method || 'GET', eventsource.URL, true);
if (eventsource.OPTIONS && eventsource.OPTIONS.headers) {
Object.keys(eventsource.OPTIONS.headers).forEach(key => {
xhr.setRequestHeader(key, eventsource.OPTIONS.headers[key]);
Expand Down Expand Up @@ -120,7 +120,11 @@ var EventSource = function (url, options) {
{ type: 'error', message: this.responseText });
}

xhr.send();
if (eventsource.OPTIONS.body) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure how xhr.send() will handle undefined as an argument, but making the assumption that it does work, why not write this just as xhr.send(eventsource.OPTIONS.body); without the if statement?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had done that before just in case somebody sent something falsy but not undefined. But I made it an if just to be clearer.

xhr.send(eventsource.OPTIONS.body);
} else {
xhr.send();
}

if (xhr.timeout > 0) {
setTimeout(function () {
Expand Down