Skip to content

Commit

Permalink
feat: Basic GET Support for Request objects
Browse files Browse the repository at this point in the history
`node-fetch` does not yet support webstreams, which is required for `.body` node-fetch/node-fetch#387
  • Loading branch information
d-goog committed Sep 11, 2024
1 parent a7e2e83 commit 8413f68
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
12 changes: 1 addition & 11 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,6 @@ export interface GaxiosOptions extends RequestInit {
*/
baseUrl?: string;
baseURL?: string | URL;
method?:
| 'GET'
| 'HEAD'
| 'POST'
| 'DELETE'
| 'PUT'
| 'CONNECT'
| 'OPTIONS'
| 'TRACE'
| 'PATCH';
/**
* The data to send in the {@link RequestInit.body} of the request. Objects will be
* serialized as JSON, except for:
Expand Down Expand Up @@ -325,7 +315,7 @@ export interface GaxiosOptionsPrepared extends GaxiosOptions {
}

/**
* Configuration for the Gaxios `request` method.
* Gaxios retry configuration.
*/
export interface RetryConfig {
/**
Expand Down
1 change: 0 additions & 1 deletion src/gaxios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ export class Gaxios {
if (!preparedHeaders.has('accept') && opts.responseType === 'json') {
preparedHeaders.set('accept', 'application/json');
}
opts.method = opts.method || 'GET';

const proxy =
opts.proxy ||
Expand Down
5 changes: 3 additions & 2 deletions src/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ function shouldRetryRequest(err: GaxiosError) {

// Only retry with configured HttpMethods.
if (
!err.config.method ||
config.httpMethodsToRetry!.indexOf(err.config.method.toUpperCase()) < 0
config.httpMethodsToRetry!.indexOf(
err.config.method?.toUpperCase() || 'GET'
) < 0
) {
return false;
}
Expand Down
13 changes: 10 additions & 3 deletions test/test.getch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,18 @@ describe('🚙 error handling', () => {
});

describe('🥁 configuration options', () => {
it('should accept URL objects', async () => {
it('should accept `URL` objects', async () => {
const scope = nock(url).get('/').reply(204);
const res = await request({url: new URL(url)});
scope.done();
assert.strictEqual(res.config.method, 'GET');
assert.strictEqual(res.status, 204);
});

it('should accept `Request` objects', async () => {
const scope = nock(url).get('/').reply(204);
const res = await request(new Request(url));
scope.done();
assert.strictEqual(res.status, 204);
});

it('should use options passed into the constructor', async () => {
Expand Down Expand Up @@ -686,7 +693,7 @@ describe('🥁 configuration options', () => {
});

describe('🎏 data handling', () => {
it('should accpet a ReadableStream as request data', async () => {
it.only('should accpet a ReadableStream as request data', async () => {
const body = fs.createReadStream('package.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const contents = require('../../package.json');
Expand Down

0 comments on commit 8413f68

Please sign in to comment.