Permalink
Browse files

fix(rest): make sure passed options don't leak

  • Loading branch information...
RangerRick committed Jul 25, 2017
1 parent d21e5e1 commit 9b9dee4677c956faff6f0f38d59de07f0d8077b5
Showing with 12 additions and 7 deletions.
  1. +6 −4 src/rest/AxiosHTTP.ts
  2. +6 −3 src/rest/GrafanaHTTP.ts
View
@@ -1,6 +1,7 @@
import axios from 'axios';
import {AxiosStatic, AxiosInstance, AxiosRequestConfig} from 'axios';
import * as qs from 'qs';
import clonedeep from 'lodash.clonedeep';
/** @hidden */
// tslint:disable-next-line
@@ -73,7 +74,7 @@ export class AxiosHTTP extends AbstractHTTP {
}
/**
* Make an HTTP put call using `axios.request({method:'put'})`.
* Make an HTTP PUT call using `axios.request({method:'put'})`.
*/
public put(url: string, options?: OnmsHTTPOptions) {
const realUrl = this.getServer(options).resolveURL(url);
@@ -126,10 +127,11 @@ export class AxiosHTTP extends AbstractHTTP {
}
if (allOptions.headers) {
ret.headers = allOptions.headers;
ret.headers = clonedeep(allOptions.headers);
} else {
ret.headers = {};
}
ret.headers = ret.headers || {};
if (!ret.headers.accept) {
ret.headers.accept = 'application/json';
}
@@ -152,7 +154,7 @@ export class AxiosHTTP extends AbstractHTTP {
}
if (allOptions.parameters) {
ret.params = Object.assign({}, allOptions.parameters);
ret.params = clonedeep(allOptions.parameters);
}
return ret;
View
@@ -7,6 +7,8 @@ import {OnmsServer} from '../api/OnmsServer';
import {log, catRest} from '../api/Log';
import {Category} from 'typescript-logging';
import clonedeep from 'lodash.clonedeep';
/** @hidden */
const catGrafana = new Category('grafana', catRest);
@@ -81,10 +83,11 @@ export class GrafanaHTTP extends AbstractHTTP {
const ret = {} as any;
if (allOptions.headers) {
ret.headers = allOptions.headers;
ret.headers = clonedeep(allOptions.headers);
} else {
ret.headers = {};
}
ret.headers = ret.headers || {};
if (!ret.headers.accept) {
ret.headers.accept = 'application/json';
}
@@ -107,7 +110,7 @@ export class GrafanaHTTP extends AbstractHTTP {
}
if (allOptions.parameters && Object.keys(allOptions.parameters).length > 0) {
ret.params = options.parameters;
ret.params = clonedeep(allOptions.parameters);
}
return ret;

0 comments on commit 9b9dee4

Please sign in to comment.