зеркало из https://github.com/Azure/ms-rest-js.git
Add redirected and url to response to mimic the node-fetch response.
This commit is contained in:
Родитель
d7059314fa
Коммит
0c9b5f3f87
|
@ -161,6 +161,8 @@ export abstract class FetchHttpClient implements HttpClient {
|
|||
? ((response.body as unknown) as NodeJS.ReadableStream)
|
||||
: undefined,
|
||||
bodyAsText: !httpRequest.streamResponseBody ? await response.text() : undefined,
|
||||
redirected: response.redirected,
|
||||
url: response.url,
|
||||
};
|
||||
|
||||
const onDownloadProgress = httpRequest.onDownloadProgress;
|
||||
|
|
|
@ -67,6 +67,16 @@ export interface HttpOperationResponse extends HttpResponse {
|
|||
* Always undefined in the browser.
|
||||
*/
|
||||
readableStreamBody?: NodeJS.ReadableStream;
|
||||
|
||||
/**
|
||||
* The redirected property indicates whether the response is the result of a request which was redirected.
|
||||
*/
|
||||
redirected?: boolean;
|
||||
|
||||
/**
|
||||
* The url property contains the URL of the response. The value will be the final URL obtained after any redirects.
|
||||
*/
|
||||
url?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -60,8 +60,19 @@ function handleRedirect(
|
|||
|
||||
return policy._nextPolicy
|
||||
.sendRequest(request)
|
||||
.then((res) => handleRedirect(policy, res, currentRetries + 1));
|
||||
.then((res) => handleRedirect(policy, res, currentRetries + 1))
|
||||
.then((res) => recordRedirect(res, request.url));
|
||||
}
|
||||
|
||||
return Promise.resolve(response);
|
||||
}
|
||||
|
||||
function recordRedirect(response: HttpOperationResponse, redirect: string): HttpOperationResponse {
|
||||
// only record the deepest/last redirect
|
||||
if (!response.redirected) {
|
||||
response.redirected = true;
|
||||
response.url = redirect;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче