@ts-common/azure-js-dev-tools
Version:
Developer dependencies for TypeScript related projects
170 lines • 5.06 kB
TypeScript
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
import { URLBuilder } from "./url";
/**
* A collection of HttpHeaders that can be sent with a HTTP request.
*/
export declare function getHeaderKey(headerName: string): string;
/**
* An individual header within a HttpHeaders collection.
*/
export interface HttpHeader {
/**
* The name of the header.
*/
name: string;
/**
* The value of the header.
*/
value: string;
}
/**
* A HttpHeaders collection represented as a simple JSON object.
*/
export declare type RawHttpHeaders = {
[headerName: string]: string;
};
/**
* A collection of HTTP header key/value pairs.
*/
export declare class HttpHeaders {
private readonly _headersMap;
constructor(rawHeaders?: RawHttpHeaders);
/**
* Set a header in this collection with the provided name and value. The name is
* case-insensitive.
* @param headerName The name of the header to set. This value is case-insensitive.
* @param headerValue The value of the header to set.
*/
set(headerName: string, headerValue: string | number): void;
/**
* Get the header value for the provided header name, or undefined if no header exists in this
* collection with the provided name.
* @param headerName The name of the header.
*/
get(headerName: string): string | undefined;
/**
* Get whether or not this header collection contains a header entry for the provided header name.
*/
contains(headerName: string): boolean;
/**
* Remove the header with the provided headerName. Return whether or not the header existed and
* was removed.
* @param headerName The name of the header to remove.
*/
remove(headerName: string): boolean;
/**
* Get the headers that are contained this collection as an object.
*/
rawHeaders(): RawHttpHeaders;
/**
* Get the headers that are contained in this collection as an array.
*/
headersArray(): HttpHeader[];
/**
* Get the header names that are contained in this collection.
*/
headerNames(): string[];
/**
* Get the header names that are contained in this collection.
*/
headerValues(): string[];
/**
* Get the JSON object representation of this HTTP header collection.
*/
toJson(): RawHttpHeaders;
/**
* Get the string representation of this HTTP header collection.
*/
toString(): string;
/**
* Create a deep clone/copy of this HttpHeaders collection.
*/
clone(): HttpHeaders;
}
export declare type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "OPTIONS";
/**
* An HTTP request to send to an HTTP server.
*/
export interface HttpRequest {
/**
* The HTTP method that this request will be sent with.
*/
method: HttpMethod;
/**
* The URL that this request will be sent to.
*/
url: string | URLBuilder;
/**
* The headers that this request with be sent with.
*/
headers?: HttpHeaders | RawHttpHeaders;
/**
* The body to send with this request.
*/
body?: any;
}
/**
* An HTTP response received from an HTTP server.
*/
export interface HttpResponse {
/**
* The request that this response is responding to.
*/
request: HttpRequest;
/**
* The response status code.
*/
statusCode: number;
/**
* The response headers.
*/
headers: HttpHeaders;
/**
* The response body.
*/
body?: string;
}
/**
* An interface that can send HttpRequests and receive promised HttpResponses.
*/
export interface HttpClient {
/**
* Send the provided HttpRequest and get back an HttpResponse.
* @param request The HttpRequest to send.
*/
sendRequest(request: HttpRequest): Promise<HttpResponse>;
}
/**
* Get an instance of the default HttpClient.
*/
export declare function getDefaultHttpClient(): HttpClient;
/**
* Options that can be provided when creating a new NodeHttpClient.
*/
export interface NodeHttpClientOptions {
/**
* Whether or not redirects will be automatically handled. Defaults to true.
*/
handleRedirects?: boolean;
}
/**
* An HTTP client that uses the built-in Node.js http module.
*/
export declare class NodeHttpClient implements HttpClient {
private readonly handleRedirects;
constructor(options?: NodeHttpClientOptions);
sendRequest(request: HttpRequest): Promise<HttpResponse>;
}
/**
* A fake HttpClient that can registered pre-determined HttpResponses for HttpRequests.
*/
export declare class FakeHttpClient implements HttpClient {
private readonly fakeResponses;
add(requestMethod: HttpMethod, requestUrl: string | URLBuilder, responseStatusCode?: number, responseHeaders?: HttpHeaders, responseBody?: string): FakeHttpClient;
sendRequest(request: HttpRequest): Promise<HttpResponse>;
}
//# sourceMappingURL=http.d.ts.map