Skip to content

Commit

Permalink
Allow to override default request headers sent by EventSource.
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciechkrol committed Oct 20, 2023
1 parent 0ad8aa3 commit a16e01c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/EventSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ class EventSource {
this._xhr.withCredentials = true;
}

this._xhr.setRequestHeader('Accept', 'text/event-stream');
this._xhr.setRequestHeader('Cache-Control', 'no-cache');
this._xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

if (this.headers) {
for (const [key, value] of Object.entries(this.headers)) {
this._xhr.setRequestHeader(key, value);
}
}

this._xhr.setRequestHeader('Accept', 'text/event-stream');
this._xhr.setRequestHeader('Cache-Control', 'no-cache');
this._xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

if (this.lastEventId !== null) {
this._xhr.setRequestHeader('Last-Event-ID', this.lastEventId);
}
Expand Down

0 comments on commit a16e01c

Please sign in to comment.