diff --git a/src/common.ts b/src/common.ts index d17da402..6affbd23 100644 --- a/src/common.ts +++ b/src/common.ts @@ -38,12 +38,17 @@ export interface Headers { } export type GaxiosPromise = Promise>; +export interface GaxiosXMLHttpRequest { + responseURL: string; +} + export interface GaxiosResponse { config: GaxiosOptions; data: T; status: number; statusText: string; headers: Headers; + request: GaxiosXMLHttpRequest; } /** diff --git a/src/gaxios.ts b/src/gaxios.ts index fdf5101d..7021009b 100644 --- a/src/gaxios.ts +++ b/src/gaxios.ts @@ -250,6 +250,11 @@ export class Gaxios { headers, status: res.status, statusText: res.statusText, + + // XMLHttpRequestLike + request: { + responseURL: res.url, + }, }; } } diff --git a/test/test.getch.ts b/test/test.getch.ts index 3af418b8..e549f2bb 100644 --- a/test/test.getch.ts +++ b/test/test.getch.ts @@ -121,6 +121,7 @@ describe('🥁 configuration options', () => { const res = await request({url}); scopes.forEach(x => x.done()); assert.deepStrictEqual(res.data, body); + assert.strictEqual(res.request.responseURL, `${url}/foo`); }); it('should support disabling redirects', async () => { @@ -139,6 +140,9 @@ describe('🥁 configuration options', () => { status: 200, statusText: 'OK', headers: {}, + request: { + responseURL: url, + }, }; const adapter = (options: GaxiosOptions) => { return Promise.resolve(response);