Skip to content

Commit

Permalink
fix(xmlhttprequest): add support xhr.responseURL (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
ykzts authored Jul 31, 2020
1 parent 00e3267 commit 606a39a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/xmlhttprequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget {
throw new DOMException('', 'InvalidAccessError');
}

this.#responseURL = '';

let parsedURL: URL;

try {
Expand Down Expand Up @@ -427,6 +429,8 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget {
this.#statusText = response.statusMessage ?? '';
this.#responseHeaders = response.headers;

this.#responseURL = `${protocol}//${parsedURL.host}${path}`;

response.addListener('data', (chunk: Buffer) => {
if (this.#responseBuffer.length === 0) {
this.dispatchEvent(new ProgressEvent('loadstart'));
Expand Down
19 changes: 19 additions & 0 deletions test/integration/xmlhttprequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,25 @@ describe('XMLHttpRequest', () => {
});
});

describe('.responseURL', () => {
it('', (done) => {
const client = new XMLHttpRequest();

client.addEventListener('loadstart', () => {
expect(client.responseURL).toBe('');
});

client.addEventListener('load', () => {
expect(client.responseURL).toMatch(/http:\/\/localhost:\d+\/path\/to/);

done();
});

client.open('GET', `${baseURL}/path/to`);
client.send(null);
});
});

describe('.withCredentials', () => {
it('throws InvalidStateError when readyState is DONE', (done) => {
const client = new XMLHttpRequest();
Expand Down

0 comments on commit 606a39a

Please sign in to comment.