-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core-https] Implement
HttpsClient
interface for node and browser (#…
…9082) Adds new clients for actually making requests over a transport layer. The XhrClient was relatively unchanged from before, but the Node client now directly uses Node's `https` module, which should provide us with more flexibility in the future for customizing how requests are made.
- Loading branch information
Showing
25 changed files
with
1,769 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
import * as base from "./rollup.base.config"; | ||
|
||
export default [base.nodeConfig(true), base.browserConfig(true)]; | ||
const inputs = []; | ||
|
||
if (!process.env.ONLY_BROWSER) { | ||
inputs.push(base.nodeConfig(true)); | ||
} | ||
|
||
if (!process.env.ONLY_NODE) { | ||
inputs.push(base.browserConfig(true)); | ||
} | ||
|
||
export default inputs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
export { XhrHttpsClient as DefaultHttpsClient } from "./xhrHttpsClient"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
export { NodeHttpsClient as DefaultHttpsClient } from "./nodeHttpsClient"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { HttpHeaders, RawHttpHeaders } from "./interfaces"; | ||
|
||
function normalizeName(name: string): string { | ||
return name.toLowerCase(); | ||
} | ||
|
||
class HttpHeadersImpl implements HttpHeaders { | ||
private readonly _headersMap: Map<string, string>; | ||
|
||
constructor(rawHeaders?: RawHttpHeaders) { | ||
this._headersMap = new Map<string, string>(); | ||
if (rawHeaders) { | ||
for (const headerName of Object.keys(rawHeaders)) { | ||
this.set(headerName, rawHeaders[headerName]); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Set a header in this collection with the provided name and value. The name is | ||
* case-insensitive. | ||
* @param name The name of the header to set. This value is case-insensitive. | ||
* @param value The value of the header to set. | ||
*/ | ||
public set(name: string, value: string | number): void { | ||
this._headersMap.set(normalizeName(name), String(value)); | ||
} | ||
|
||
/** | ||
* Get the header value for the provided header name, or undefined if no header exists in this | ||
* collection with the provided name. | ||
* @param name The name of the header. This value is case-insensitive. | ||
*/ | ||
public get(name: string): string | undefined { | ||
return this._headersMap.get(normalizeName(name)); | ||
} | ||
|
||
/** | ||
* Get whether or not this header collection contains a header entry for the provided header name. | ||
* @param name The name of the header to set. This value is case-insensitive. | ||
*/ | ||
public has(name: string): boolean { | ||
return this._headersMap.has(normalizeName(name)); | ||
} | ||
|
||
/** | ||
* Remove the header with the provided headerName. | ||
* @param name The name of the header to remove. | ||
*/ | ||
public delete(name: string): void { | ||
this._headersMap.delete(normalizeName(name)); | ||
} | ||
|
||
/** | ||
* Get the JSON object representation of this HTTP header collection. | ||
*/ | ||
public toJSON(): RawHttpHeaders { | ||
const result: RawHttpHeaders = {}; | ||
for (const [key, value] of this._headersMap) { | ||
result[key] = value; | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* Get the string representation of this HTTP header collection. | ||
*/ | ||
public toString(): string { | ||
return JSON.stringify(this.toJSON()); | ||
} | ||
|
||
/** | ||
* Create a deep clone/copy of this HttpHeaders collection. | ||
*/ | ||
public clone(): HttpHeaders { | ||
return new HttpHeadersImpl(this.toJSON()); | ||
} | ||
|
||
/** | ||
* Iterate over tuples of header [name, value] pairs. | ||
*/ | ||
[Symbol.iterator](): Iterator<[string, string]> { | ||
return this._headersMap.entries(); | ||
} | ||
} | ||
|
||
/** | ||
* Creates an object that satisfies the `HttpHeaders` interface. | ||
* @param rawHeaders A simple object representing initial headers | ||
*/ | ||
export function createHttpHeaders(rawHeaders?: RawHttpHeaders): HttpHeaders { | ||
return new HttpHeadersImpl(rawHeaders); | ||
} |
Oops, something went wrong.