Skip to content

Commit

Permalink
fix(:bug:): ensure that custom headers arent misidentified as request…
Browse files Browse the repository at this point in the history
… parameters

AFFECTS PACKAGES:
@esri/arcgis-rest-request

ISSUES CLOSED: #290
  • Loading branch information
jgravois committed Jan 20, 2019
1 parent 4621146 commit 4ff33b1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import { IRequestOptions } from "../request";

/**
* Helper for methods with lots of first order request options to pass them through as request parameters.
* Helper for methods with lots of first order request options to pass through as request parameters.
*/
export function appendCustomParams(
oldOptions: IRequestOptions,
newOptions: IRequestOptions
) {
// at v2.0.0, this should be refactored as a nonmutating method that takes a single argument, mixes in everything and returns a new instance of IRequestOptions

// only pass query parameters through in the request, not generic IRequestOptions props
Object.keys(oldOptions).forEach(function(key: string) {
if (
Expand All @@ -20,6 +22,7 @@ export function appendCustomParams(
key !== "fetch" &&
key !== "portal" &&
key !== "maxUrlLength" &&
key !== "headers" &&
key !== "endpoint" &&
key !== "decodeValues"
) {
Expand Down
32 changes: 32 additions & 0 deletions packages/arcgis-rest-request/test/utils/append-params.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Copyright (c) 2018-2019 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import { appendCustomParams, IRequestOptions } from "../../src/index";

describe("appendCustomParams", () => {
it("should not mis-identify standard request options as parameters.", () => {
const oldOptions: any = {
foo: "bar",
headers: {
Cookie: "monster"
},
httpMethod: "GET",
params: { baz: "luhrman" },
maxUrlLength: 1064
};

const newOptions: IRequestOptions = {
params: {}
};

appendCustomParams(oldOptions, newOptions);

// all other request options should be mixed in outside this helper method
expect(typeof newOptions.headers).toEqual("undefined");
expect(typeof newOptions.httpMethod).toEqual("undefined");
expect(typeof newOptions.maxUrlLength).toEqual("undefined");
expect(typeof newOptions.params.baz).toEqual("undefined");

expect(newOptions.params.foo).toEqual("bar");
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
/* Copyright (c) 2018-2019 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import { processParams, requiresFormData } from "../../src/index";
Expand Down

0 comments on commit 4ff33b1

Please sign in to comment.