apify-client 2.26.1-beta.0 → 2.26.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -68,9 +68,9 @@ export declare class ActorServerClient extends ResourceClient {
|
|
|
68
68
|
* Unavailable (503) response is retried with the client's retry settings, and the last one is returned once the
|
|
69
69
|
* retries run out. The Actor's code can return these statuses too, and then it gets the request again. Network
|
|
70
70
|
* errors and timeouts are not retried, since the Actor may have already handled the request. A redirect is
|
|
71
|
-
* returned as it is, since following it would send the token to a host the Actor's code picked.
|
|
72
|
-
*
|
|
73
|
-
* the Actor's server may not decode a compressed body.
|
|
71
|
+
* returned as it is, since following it would send the token to a host the Actor's code picked. In a browser the
|
|
72
|
+
* redirect response can't be read, so the request fails with an error instead. Request bodies are sent
|
|
73
|
+
* uncompressed, since the Actor's server may not decode a compressed body.
|
|
74
74
|
*
|
|
75
75
|
* @template T - Type of the parsed response body.
|
|
76
76
|
* @param path - The path on the Actor's server, for example `/search`. It is always resolved against the server
|
|
@@ -153,6 +153,9 @@ class ActorServerClient extends resource_client_1.ResourceClient {
|
|
|
153
153
|
// The token goes in `X-Apify-Authorization`, which the platform strips, and the client's default
|
|
154
154
|
// `Authorization` header is dropped (`null`) so the caller's own one, if any, reaches the Actor.
|
|
155
155
|
const authHeaders = { Authorization: null };
|
|
156
|
+
// The fetch adapter adds a `User-Agent` of its own otherwise, which a browser lists in the CORS preflight.
|
|
157
|
+
if (!(0, utils_1.isNode)())
|
|
158
|
+
authHeaders['User-Agent'] = null;
|
|
156
159
|
if (this.apifyClient.token)
|
|
157
160
|
authHeaders['X-Apify-Authorization'] = `Bearer ${this.apifyClient.token}`;
|
|
158
161
|
const requestHeaders = mergeHeaders(mergeHeaders(authHeaders, headers), parentRequestId === undefined ? undefined : { 'X-Actor-Request-ID': parentRequestId });
|
|
@@ -173,7 +176,15 @@ class ActorServerClient extends resource_client_1.ResourceClient {
|
|
|
173
176
|
config.forceBuffer = true;
|
|
174
177
|
if (responseType === 'stream')
|
|
175
178
|
config.responseType = 'stream';
|
|
176
|
-
|
|
179
|
+
// The browser follows the redirects of an XHR itself, while the fetch adapter honors `maxRedirects: 0`.
|
|
180
|
+
if (!(0, utils_1.isNode)())
|
|
181
|
+
config.adapter = 'fetch';
|
|
182
|
+
const response = await this.httpClient.call(config);
|
|
183
|
+
// `redirect: 'manual'` resolves to an opaque response with status 0 instead of the redirect.
|
|
184
|
+
if (!(0, utils_1.isNode)() && response.status === 0) {
|
|
185
|
+
throw new Error(`${method} ${config.url} responded with a redirect, which the client does not follow.`);
|
|
186
|
+
}
|
|
187
|
+
return response;
|
|
177
188
|
}
|
|
178
189
|
/**
|
|
179
190
|
* Fetches the Actor, checks that it is a Server Actor, and caches its server URL.
|