forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Azure#84 from RikkiGibson/HttpClient
Don't expose fetch types in HttpOperationResponse
- Loading branch information
Showing
11 changed files
with
255 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
/** | ||
* A collection of HttpHeaders that can be sent with a HTTP request. | ||
*/ | ||
function getHeaderKey(headerName: string) { | ||
return headerName.toLowerCase(); | ||
} | ||
|
||
/** | ||
* 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 type RawHttpHeaders = { [headerName: string]: string }; | ||
|
||
/** | ||
* A collection of HTTP header key/value pairs. | ||
*/ | ||
export class HttpHeaders { | ||
private readonly _headersMap: { [headerKey: string]: HttpHeader }; | ||
|
||
constructor(rawHeaders?: RawHttpHeaders) { | ||
this._headersMap = {}; | ||
if (rawHeaders) { | ||
for (const headerName in rawHeaders) { | ||
this.set(headerName, rawHeaders[headerName]); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* 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. | ||
*/ | ||
public set(headerName: string, headerValue: string | number): void { | ||
this._headersMap[getHeaderKey(headerName)] = { name: headerName, value: headerValue.toString() }; | ||
} | ||
|
||
/** | ||
* 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. | ||
*/ | ||
public get(headerName: string): string | undefined { | ||
const header: HttpHeader = this._headersMap[getHeaderKey(headerName)]; | ||
return !header ? undefined : header.value; | ||
} | ||
|
||
/** | ||
* Get whether or not this header collection contains a header entry for the provided header name. | ||
*/ | ||
public contains(headerName: string): boolean { | ||
return !!this._headersMap[getHeaderKey(headerName)]; | ||
} | ||
|
||
/** | ||
* 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. | ||
*/ | ||
public remove(headerName: string): boolean { | ||
const result: boolean = this.contains(headerName); | ||
delete this._headersMap[getHeaderKey(headerName)]; | ||
return result; | ||
} | ||
|
||
/** | ||
* Get the headers that are contained this collection as an object. | ||
*/ | ||
public rawHeaders(): RawHttpHeaders { | ||
const result: RawHttpHeaders = {}; | ||
for (const headerKey in this._headersMap) { | ||
const header: HttpHeader = this._headersMap[headerKey]; | ||
result[header.name] = header.value; | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* Get the headers that are contained in this collection as an array. | ||
*/ | ||
public headersArray(): HttpHeader[] { | ||
const headers: HttpHeader[] = []; | ||
for (const headerKey in this._headersMap) { | ||
headers.push(this._headersMap[headerKey]); | ||
} | ||
return headers; | ||
} | ||
|
||
/** | ||
* Get the header names that are contained in this collection. | ||
*/ | ||
public headerNames(): string[] { | ||
const headerNames: string[] = []; | ||
const headers: HttpHeader[] = this.headersArray(); | ||
for (let i = 0; i < headers.length; ++i) { | ||
headerNames.push(headers[i].name); | ||
} | ||
return headerNames; | ||
} | ||
|
||
/** | ||
* Get the header names that are contained in this collection. | ||
*/ | ||
public headerValues(): string[] { | ||
const headerValues: string[] = []; | ||
const headers: HttpHeader[] = this.headersArray(); | ||
for (let i = 0; i < headers.length; ++i) { | ||
headerValues.push(headers[i].value); | ||
} | ||
return headerValues; | ||
} | ||
|
||
/** | ||
* Get the JSON object representation of this HTTP header collection. | ||
*/ | ||
public toJson(): RawHttpHeaders { | ||
const result: RawHttpHeaders = {}; | ||
|
||
const headers: HttpHeader[] = this.headersArray(); | ||
for (let i = 0; i < headers.length; ++i) { | ||
result[headers[i].name] = headers[i].value; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Create a deep clone/copy of this HttpHeaders collection. | ||
*/ | ||
public clone(): HttpHeaders { | ||
return new HttpHeaders(this.rawHeaders()); | ||
} | ||
} |
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,50 +1,39 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
import { WebResource, RequestPrepareOptions, HttpMethods, ParameterValue, RequestOptionsBase } from "./webResource"; | ||
import { FetchHttpClient } from "./fetchHttpClient"; | ||
import { HttpClient } from "./httpClient"; | ||
import { HttpOperationResponse } from "./httpOperationResponse"; | ||
import { HttpPipelineLogger } from "./httpPipelineLogger"; | ||
import { HttpPipelineLogLevel } from "./httpPipelineLogLevel"; | ||
export { WebResource, RequestPrepareOptions, HttpMethods, ParameterValue, RequestOptionsBase } from "./webResource"; | ||
export { FetchHttpClient } from "./fetchHttpClient"; | ||
export { HttpClient } from "./httpClient"; | ||
export { HttpOperationResponse } from "./httpOperationResponse"; | ||
export { HttpPipelineLogger } from "./httpPipelineLogger"; | ||
export { HttpPipelineLogLevel } from "./httpPipelineLogLevel"; | ||
export { RestError } from "./restError"; | ||
export { OperationSpec } from "./operationSpec"; | ||
import { RestError } from "./restError"; | ||
import { ServiceClient, ServiceClientOptions } from "./serviceClient"; | ||
import { Constants } from "./util/constants"; | ||
import { logPolicy } from "./policies/logPolicy"; | ||
import { BaseRequestPolicy, RequestPolicy } from "./policies/requestPolicy"; | ||
import { exponentialRetryPolicy } from "./policies/exponentialRetryPolicy"; | ||
import { systemErrorRetryPolicy } from "./policies/systemErrorRetryPolicy"; | ||
import { redirectPolicy } from "./policies/redirectPolicy"; | ||
import { signingPolicy } from "./policies/signingPolicy"; | ||
import { msRestUserAgentPolicy } from "./policies/msRestUserAgentPolicy"; | ||
import { | ||
export { ServiceClient, ServiceClientOptions } from "./serviceClient"; | ||
export { Constants } from "./util/constants"; | ||
export { logPolicy } from "./policies/logPolicy"; | ||
export { BaseRequestPolicy, RequestPolicy } from "./policies/requestPolicy"; | ||
export { exponentialRetryPolicy } from "./policies/exponentialRetryPolicy"; | ||
export { systemErrorRetryPolicy } from "./policies/systemErrorRetryPolicy"; | ||
export { redirectPolicy } from "./policies/redirectPolicy"; | ||
export { signingPolicy } from "./policies/signingPolicy"; | ||
export { msRestUserAgentPolicy } from "./policies/msRestUserAgentPolicy"; | ||
export { | ||
BaseMapperType, CompositeMapper, DictionaryMapper, EnumMapper, Mapper, | ||
MapperConstraints, MapperType, PolymorphicDiscriminator, | ||
SequenceMapper, Serializer, UrlParameterValue, serializeObject | ||
} from "./serializer"; | ||
import { | ||
export { | ||
stripRequest, stripResponse, delay, | ||
executePromisesSequentially, generateUuid, encodeUri, ServiceCallback, | ||
promiseToCallback, promiseToServiceCallback, isValidUuid, | ||
applyMixins, isNode, stringifyXML, prepareXMLRootList, isDuration | ||
} from "./util/utils"; | ||
import { URLBuilder, URLQuery } from "./url"; | ||
export { URLBuilder, URLQuery } from "./url"; | ||
|
||
// Credentials | ||
import { TokenCredentials } from "./credentials/tokenCredentials"; | ||
import { BasicAuthenticationCredentials } from "./credentials/basicAuthenticationCredentials"; | ||
import { ApiKeyCredentials, ApiKeyCredentialOptions } from "./credentials/apiKeyCredentials"; | ||
import { ServiceClientCredentials } from "./credentials/serviceClientCredentials"; | ||
import * as isStream from "is-stream"; | ||
|
||
export { | ||
BaseMapperType, CompositeMapper, DictionaryMapper, EnumMapper, Mapper, MapperConstraints, MapperType, FetchHttpClient, | ||
PolymorphicDiscriminator, SequenceMapper, UrlParameterValue, Serializer, serializeObject, HttpClient, HttpPipelineLogger, HttpPipelineLogLevel, TokenCredentials, | ||
WebResource, RequestPrepareOptions, HttpMethods, ParameterValue, HttpOperationResponse, ServiceClient, Constants, | ||
BasicAuthenticationCredentials, ApiKeyCredentials, ApiKeyCredentialOptions, ServiceClientCredentials, BaseRequestPolicy, logPolicy, ServiceClientOptions, exponentialRetryPolicy, | ||
systemErrorRetryPolicy, signingPolicy, msRestUserAgentPolicy, stripRequest, stripResponse, delay, executePromisesSequentially, | ||
generateUuid, isValidUuid, encodeUri, RestError, RequestOptionsBase, RequestPolicy, ServiceCallback, promiseToCallback, | ||
promiseToServiceCallback, isStream, redirectPolicy, applyMixins, isNode, stringifyXML, prepareXMLRootList, isDuration, | ||
URLBuilder, URLQuery | ||
}; | ||
export { TokenCredentials } from "./credentials/tokenCredentials"; | ||
export { BasicAuthenticationCredentials } from "./credentials/basicAuthenticationCredentials"; | ||
export { ApiKeyCredentials, ApiKeyCredentialOptions } from "./credentials/apiKeyCredentials"; | ||
export { ServiceClientCredentials } from "./credentials/serviceClientCredentials"; | ||
export const isStream = require("is-stream"); |
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
Oops, something went wrong.