Skip to content

Commit

Permalink
feat: adds agentkeepalive (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
moltar authored Nov 12, 2021
1 parent 991f615 commit b14492e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
25 changes: 20 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"license": "MIT",
"dependencies": {
"@scaleleap/amazon-marketplaces": "12.0.1",
"agentkeepalive": "4.1.4",
"axios": "0.24.0",
"client-oauth2": "4.3.3",
"fp-ts": "2.11.5",
Expand Down
12 changes: 12 additions & 0 deletions src/axios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Axios from 'axios'
import { USER_AGENT } from './constants'
import Agent from 'agentkeepalive'

export const axios = Axios.create({
httpAgent: new Agent(),
headers: {
'User-Agent': USER_AGENT,
},
})

export * from 'axios'
8 changes: 2 additions & 6 deletions src/http-client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios, { Method, AxiosResponse } from 'axios'
import { axios, Method, AxiosResponse } from './axios'
import HttpStatus from 'http-status-codes'

import { USER_AGENT, JSON_CONTENT_TYPE } from './constants'
import { JSON_CONTENT_TYPE } from './constants'
import { apiErrorFactory, NullError, InvalidProgramStateError } from './errors'
import gunzip from './gunzip'
import { inspect } from 'util'
Expand Down Expand Up @@ -30,7 +30,6 @@ export class HttpClient {
'Content-Type': JSON_CONTENT_TYPE,
Authorization: `Bearer ${this.auth.accessToken}`,
'Amazon-Advertising-API-ClientId': this.auth.clientId,
'User-Agent': USER_AGENT,
}

if (this.auth.scope) {
Expand Down Expand Up @@ -193,9 +192,6 @@ export class HttpClient {

const download = await axios.get<ArrayBuffer>(location, {
responseType: 'arraybuffer',
headers: {
'User-Agent': USER_AGENT,
},
})

if (download.status !== this.httpStatus.OK) {
Expand Down
2 changes: 1 addition & 1 deletion src/o-auth-client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ClientOAuth2 from 'client-oauth2'
import { Options } from 'client-oauth2'
import axios, { Method } from 'axios'
import { defaultsDeep } from 'lodash'
import { USER_AGENT } from './constants'
import { Marketplace } from './maketplace'
import type { Headers } from './http-client'
import { axios, Method } from './axios'

const request: ClientOAuth2.Request = async (
method,
Expand Down

0 comments on commit b14492e

Please sign in to comment.