PageSourceSearch

https://www.darpa.mil/themes/custom/darpa_uswds/assets/js/packages…/apigatewaycore/simplehttpclient.js?tm7so2

js darpa.mil collected 2026-10-01 07:16:04 UTC 2,966 bytes, 81 lines download raw bytes

1/*
2 * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 *  http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15 
16var apiGateway = apiGateway || {};
17apiGateway.core = apiGateway.core || {};
18
19apiGateway.core.simpleHttpClientFactory = {};
20apiGateway.core.simpleHttpClientFactory.newClient = function (config) {
21    function buildCanonicalQueryString(queryParams) {
22        //Build a properly encoded query string from a QueryParam object
23        if (Object.keys(queryParams).length < 1) {
24            return '';
25        }
26
27        var canonicalQueryString = '';
28        for (var property in queryParams) {
29            if (queryParams.hasOwnProperty(property)) {
30                canonicalQueryString += encodeURIComponent(property) + '=' + encodeURIComponent(queryParams[property]) + '&';
31            }
32        }
33
34        return canonicalQueryString.substr(0, canonicalQueryString.length - 1);
35    }
36
37    var simpleHttpClient = { };
38    simpleHttpClient.endpoint = apiGateway.core.utils.assertDefined(config.endpoint, 'endpoint');
39
40    simpleHttpClient.makeRequest = function (request) {
41        var verb = apiGateway.core.utils.assertDefined(request.verb, 'verb');
42        var path = apiGateway.core.utils.assertDefined(request.path, 'path');
43        var queryParams = apiGateway.core.utils.copy(request.queryParams);
44        if (queryParams === undefined) {
45            queryParams = {};
46        }
47        var headers = apiGateway.core.utils.copy(request.headers);
48        if (headers === undefined) {
49            headers = {};
50        }
51
52        //If the user has not specified an override for Content type the use default
53        if(headers['Content-Type'] === undefined) {
54            headers['Content-Type'] = config.defaultContentType;
55        }
56
57        //If the user has not specified an override for Accept type the use default
58        if(headers['Accept'] === undefined) {
59            headers['Accept'] = config.defaultAcceptType;
60        }
61
62        var body = apiGateway.core.utils.copy(request.body);
63        if (body === undefined) {
64            body = '';
65        }
66
67        var url = config.endpoint + path;
68        var queryString = buildCanonicalQueryString(queryParams);
69        if (queryString != '') {
70            url += '?' + queryString;
71        }
72        var simpleHttpRequest = {
73            method: verb,
74            url: url,
75            headers: headers,
76            data: body
77        };
78        return axios(simpleHttpRequest);
79    };
80    return simpleHttpClient;
81};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.