Skip to content

Commit

Permalink
chore(deps): use gaxios for http requests (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Nov 21, 2018
1 parent 58a183a commit ab73dbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@
"author": "Stephen Sawchuk",
"license": "MIT",
"dependencies": {
"axios": "^0.18.0",
"json-bigint": "^0.3.0",
"retry-axios": "0.3.2"
"gaxios": "^1.0.2",
"json-bigint": "^0.3.0"
},
"devDependencies": {
"@types/execa": "^0.9.0",
Expand Down
21 changes: 7 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
* See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/

import axios from 'axios';
import {request} from 'gaxios';
import {OutgoingHttpHeaders} from 'http';
import * as rax from 'retry-axios';

const jsonBigint = require('json-bigint');

export const HOST_ADDRESS = 'http://metadata.google.internal';
Expand Down Expand Up @@ -56,18 +54,13 @@ async function metadataAccessor<T>(
property = '/' + options.property;
}
validate(options);
const ax = axios.create({
transformResponse: [t => t] // Do not use default JSON.parse.
});
rax.attach(ax);
const reqOpts = {
url: `${BASE_URL}/${type}${property}`,
headers: Object.assign({}, HEADERS, options.headers),
raxConfig: {noResponseRetries, instance: ax},
params: options.params
};
try {
const res = await ax.request<T>(reqOpts);
const res = await request<T>({
url: `${BASE_URL}/${type}${property}`,
headers: Object.assign({}, HEADERS, options.headers),
retryConfig: {noResponseRetries},
params: options.params
});
// NOTE: node.js converts all incoming headers to lower case.
if (res.headers[HEADER_NAME.toLowerCase()] !== HEADER_VALUE) {
throw new Error(`Invalid response from metadata service: incorrect ${
Expand Down

0 comments on commit ab73dbd

Please sign in to comment.