Skip to content
This repository was archived by the owner on Apr 15, 2023. It is now read-only.

Commit 08de916

Browse files
djMaxjordanbyron
authored andcommitted
Allow method and body from options (#18)
* Allow method and body from options * Clearer body handling
1 parent 2474952 commit 08de916

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

EventSource.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var EventSource = function (url, options) {
3535

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

123-
xhr.send();
123+
if (eventsource.OPTIONS.body) {
124+
xhr.send(eventsource.OPTIONS.body);
125+
} else {
126+
xhr.send();
127+
}
124128

125129
if (xhr.timeout > 0) {
126130
setTimeout(function () {

0 commit comments

Comments
 (0)