From 6c8c9494080f5e45f55415061ac8fc957a36197e Mon Sep 17 00:00:00 2001 From: Sergey Bondar Date: Sat, 16 Nov 2019 00:09:06 +0300 Subject: [PATCH 1/2] feat: add XMLHttpRequest-like request in response object --- src/common.ts | 7 +++++++ src/gaxios.ts | 7 +++++++ test/test.getch.ts | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/src/common.ts b/src/common.ts index d17da402..53a74670 100644 --- a/src/common.ts +++ b/src/common.ts @@ -38,12 +38,19 @@ export interface Headers { } export type GaxiosPromise = Promise>; +export interface GaxiosXMLHttpRequest { + responseURL: string; + status: number; + statusText: 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..31d49c5f 100644 --- a/src/gaxios.ts +++ b/src/gaxios.ts @@ -250,6 +250,13 @@ export class Gaxios { headers, status: res.status, statusText: res.statusText, + + // XMLHttpRequestLike + request: { + responseURL: res.url, + status: res.status, + statusText: res.statusText, + }, }; } } diff --git a/test/test.getch.ts b/test/test.getch.ts index 3af418b8..5f47c99e 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,11 @@ describe('🥁 configuration options', () => { status: 200, statusText: 'OK', headers: {}, + request: { + responseURL: url, + status: 200, + statusText: 'OK', + }, }; const adapter = (options: GaxiosOptions) => { return Promise.resolve(response); From bfcd2f6151ec446b35e006ceb6fc7cbabc992857 Mon Sep 17 00:00:00 2001 From: Sergey Bondar Date: Sat, 23 Nov 2019 21:39:42 +0300 Subject: [PATCH 2/2] fix: response url only needed --- src/common.ts | 2 -- src/gaxios.ts | 2 -- test/test.getch.ts | 2 -- 3 files changed, 6 deletions(-) diff --git a/src/common.ts b/src/common.ts index 53a74670..6affbd23 100644 --- a/src/common.ts +++ b/src/common.ts @@ -40,8 +40,6 @@ export type GaxiosPromise = Promise>; export interface GaxiosXMLHttpRequest { responseURL: string; - status: number; - statusText: string; } export interface GaxiosResponse { diff --git a/src/gaxios.ts b/src/gaxios.ts index 31d49c5f..7021009b 100644 --- a/src/gaxios.ts +++ b/src/gaxios.ts @@ -254,8 +254,6 @@ export class Gaxios { // XMLHttpRequestLike request: { responseURL: res.url, - status: res.status, - statusText: res.statusText, }, }; } diff --git a/test/test.getch.ts b/test/test.getch.ts index 5f47c99e..e549f2bb 100644 --- a/test/test.getch.ts +++ b/test/test.getch.ts @@ -142,8 +142,6 @@ describe('🥁 configuration options', () => { headers: {}, request: { responseURL: url, - status: 200, - statusText: 'OK', }, }; const adapter = (options: GaxiosOptions) => {