-
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.
Add some other request options (#26331)
fixes Azure/autorest.typescript#1902 This PR is trying to map the [OperationOptions](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-client/src/interfaces.ts#L98-L122) from @azure/core-client to [RequestParameters](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-client-rest/src/common.ts#L19-L51) in @azure-rest/core-client. As the API layer internally call rest layer, we should provide every functionality that the high level core-client @azure-rest/core-client has and map them to the rest level core-client @azure-rest/core-client. right now I have added `abortSignal`, `tracingOptions`, `onResponse` into the RequestParameters. ```typescript /** * The signal which can be used to abort requests. */ abortSignal?: AbortSignalLike; /** * Options used when tracing is enabled. */ tracingOptions?: OperationTracingOptions; /** * A function to be called each time a response is received from the server * while performing the requested operation. * May be called multiple times. */ onResponse?: RawResponseCallback; ``` And inside the `requestOptions`, I have added `timeout`, `onUploadProgress`, `onDownloadProgress` and flattened it in the top level of `RequestParameters` ```typescript /** * The number of milliseconds a request can take before automatically being terminated. */ timeout?: number; /** * Callback which fires upon upload progress. */ onUploadProgress?: (progress: TransferProgressEvent) => void; /** * Callback which fires upon download progress. */ onDownloadProgress?: (progress: TransferProgressEvent) => void; ``` Also, add an interface OperationOptions in @azure-rest/core-client, for modular usage in specify these options. ```typescript export interface OperationOptions { /** * The signal which can be used to abort requests. */ abortSignal?: AbortSignalLike; /** * Options used when creating and sending HTTP requests for this operation. */ requestOptions?: OperationRequestOptions; /** * Options used when tracing is enabled. */ tracingOptions?: OperationTracingOptions; /** * A function to be called each time a response is received from the server * while performing the requested operation. * May be called multiple times. */ onResponse?: RawResponseCallback; } ```
- Loading branch information
Showing
7 changed files
with
207 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { OperationOptions, RequestParameters } from "./common"; | ||
|
||
/** | ||
* Helper function to convert OperationOptions to RequestParameters | ||
* @param options - the options that are used by Modular layer to send the request | ||
* @returns the result of the conversion in RequestParameters of RLC layer | ||
*/ | ||
export function operationOptionsToRequestParameters(options: OperationOptions): RequestParameters { | ||
return { | ||
allowInsecureConnection: options.requestOptions?.allowInsecureConnection, | ||
timeout: options.requestOptions?.timeout, | ||
skipUrlEncoding: options.requestOptions?.skipUrlEncoding, | ||
abortSignal: options.abortSignal, | ||
onUploadProgress: options.requestOptions?.onUploadProgress, | ||
onDownloadProgress: options.requestOptions?.onDownloadProgress, | ||
tracingOptions: options.tracingOptions, | ||
headers: { ...options.requestOptions?.headers }, | ||
onResponse: options.onResponse, | ||
}; | ||
} |
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