2
2
* The AGPL License (AGPL)
3
3
* Copyright (c) 2022 hans000
4
4
*/
5
- import { delayRun , tryToProxyUrl } from "../../tools" ;
5
+ import { delayRun } from "../../tools" ;
6
6
import { log } from "../../tools/log" ;
7
7
import { parseUrl } from "../../tools" ;
8
8
import { Options , __global__ } from "./globalVar" ;
@@ -22,9 +22,8 @@ export function proxyFetch(options: Options) {
22
22
const proxyFetch = new Proxy ( __global__ . NativeFetch , {
23
23
async apply ( target , thisArg , args ) {
24
24
const [ input , init ] = args
25
- const isRequest = input instanceof Request
26
- const req = isRequest ? input . clone ( ) : new Request ( input . toString ( ) , init )
27
- const url = isRequest
25
+ const req = input instanceof Request ? input . clone ( ) : new Request ( input . toString ( ) , init )
26
+ const url = input instanceof Request
28
27
? parseUrl ( input . url )
29
28
: input instanceof URL
30
29
? input
@@ -36,8 +35,6 @@ export function proxyFetch(options: Options) {
36
35
params : [ ...url . searchParams . entries ( ) ] ,
37
36
} )
38
37
const realFetch = __global__ . PageFetch || target
39
- const proxyUrl = tryToProxyUrl ( input , __global__ . options . proxy )
40
- const proxyInput = isRequest ? new Request ( proxyUrl , init ) : proxyUrl
41
38
42
39
if ( matchItem ) {
43
40
const loggable = options . faked && options . fakedLog
@@ -51,7 +48,7 @@ export function proxyFetch(options: Options) {
51
48
}
52
49
const realResponse = options . faked
53
50
? new Response ( new Blob ( [ 'null' ] ) )
54
- : await realFetch . call ( thisArg , proxyInput , init )
51
+ : await realFetch . call ( thisArg , input , init )
55
52
const response = await onFetchIntercept ( matchItem ) ( realResponse )
56
53
57
54
return new Promise ( resolve => {
@@ -71,11 +68,10 @@ export function proxyFetch(options: Options) {
71
68
} , matchItem ? matchItem . delay : undefined )
72
69
} )
73
70
}
74
-
75
71
if ( __global__ . PageFetch ) {
76
- return __global__ . PageFetch . call ( thisArg , proxyInput , init )
72
+ return __global__ . PageFetch . call ( thisArg , ... args )
77
73
}
78
- return target . call ( thisArg , proxyInput , init )
74
+ return target . call ( thisArg , ... args )
79
75
} ,
80
76
} )
81
77
@@ -104,4 +100,4 @@ export function unproxyFetch() {
104
100
}
105
101
} )
106
102
}
107
- }
103
+ }
0 commit comments