"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.CdmHttpRequest = void 0;
const guid_typescript_1 = require("guid-typescript");
/**
 * The CDM Http request class that is being used by CDM Http client to execute network requests.
 */
class CdmHttpRequest {
    constructor(url, numberOfRetries = 0, method) {
        this.headers = new Map();
        this.requestedUrl = url;
        this.requestId = guid_typescript_1.Guid.create().toString();
        this.numberOfRetries = numberOfRetries;
        // If there is no HTTP method specified, assume GET.
        if (method === undefined) {
            this.method = 'GET';
        }
        else {
            this.method = method;
        }
    }
    /**
     * Amount of time in milliseconds to reach the maximum timout.
     * @internal
     */
    get timeForMaximumTimeout() {
        return Math.max(this.maximumTimeout - (Date.now() - this.startTime), 0);
    }
    /**
     * If the maximum timout was exceeded or not.
     * @internal
     */
    get maximumTimeoutExceeded() {
        return this.timeForMaximumTimeout === 0;
    }
    /**
     * Marks this requests as `started` for processing.
     * @internal
     */
    start() {
        this.startTime = Date.now();
    }
    /**
     * Strips sas token parameter 'sig'.
     * @returns The requested url with the value of 'sig' replaced with 'REMOVED'.
     * @deprecated Only for internal use.
     */
    stripSasSig() {
        const sigStartIndex = this.requestedUrl.indexOf('sig=');
        if (sigStartIndex == -1) {
            return this.requestedUrl;
        }
        var sigEndIndex = this.requestedUrl.indexOf('&', sigStartIndex + 1);
        sigEndIndex = sigEndIndex == -1 ? this.requestedUrl.length : sigEndIndex;
        return this.requestedUrl.substring(0, sigStartIndex + 4) + 'REMOVED' + this.requestedUrl.substring(sigEndIndex);
    }
}
exports.CdmHttpRequest = CdmHttpRequest;
//# sourceMappingURL=CdmHttpRequest.js.map