nomagick commited on
Commit
fb43578
·
unverified ·
1 Parent(s): 8597daa

fix: curl implicit redirect

Browse files
Files changed (1) hide show
  1. src/services/curl.ts +5 -4
src/services/curl.ts CHANGED
@@ -10,7 +10,7 @@ import { AssertionFailureError, FancyFile } from 'civkit';
10
  import { ServiceBadAttemptError, TempFileManager } from '../shared';
11
  import { createBrotliDecompress, createInflate, createGunzip } from 'zlib';
12
  import { ZSTDDecompress } from 'simple-zstd';
13
- import _ from 'lodash';
14
  import { Readable } from 'stream';
15
  import { AsyncLocalContext } from './async-context';
16
 
@@ -278,9 +278,6 @@ export class CurlControl extends AsyncService {
278
  if ([301, 302, 307, 308].includes(r.statusCode)) {
279
  const headers = r.headers[r.headers.length - 1];
280
  const location = headers.Location || headers.location;
281
- if (!location) {
282
- throw new AssertionFailureError(`Failed to access ${urlToCrawl}: Bad redirection from ${nextHopUrl}`);
283
- }
284
 
285
  const setCookieHeader = headers['Set-Cookie'] || headers['set-cookie'];
286
  if (setCookieHeader) {
@@ -291,6 +288,10 @@ export class CurlControl extends AsyncService {
291
  }
292
  }
293
 
 
 
 
 
294
  nextHopUrl = new URL(location, nextHopUrl);
295
  fakeHeaderInfos.push(...r.headers);
296
  leftRedirection -= 1;
 
10
  import { ServiceBadAttemptError, TempFileManager } from '../shared';
11
  import { createBrotliDecompress, createInflate, createGunzip } from 'zlib';
12
  import { ZSTDDecompress } from 'simple-zstd';
13
+ import _, { set } from 'lodash';
14
  import { Readable } from 'stream';
15
  import { AsyncLocalContext } from './async-context';
16
 
 
278
  if ([301, 302, 307, 308].includes(r.statusCode)) {
279
  const headers = r.headers[r.headers.length - 1];
280
  const location = headers.Location || headers.location;
 
 
 
281
 
282
  const setCookieHeader = headers['Set-Cookie'] || headers['set-cookie'];
283
  if (setCookieHeader) {
 
288
  }
289
  }
290
 
291
+ if (!location && !setCookieHeader) {
292
+ throw new AssertionFailureError(`Failed to access ${urlToCrawl}: Bad redirection from ${nextHopUrl}`);
293
+ }
294
+
295
  nextHopUrl = new URL(location, nextHopUrl);
296
  fakeHeaderInfos.push(...r.headers);
297
  leftRedirection -= 1;