@@ -17,7 +17,13 @@ import { op_fetch_custom_client } from "ext:core/ops";
17
17
import { loadTlsKeyPair } from "ext:deno_net/02_tls.js" ;
18
18
19
19
const { internalRidSymbol } = core ;
20
- const { ObjectDefineProperty } = primordials ;
20
+ const {
21
+ JSONStringify,
22
+ ObjectDefineProperty,
23
+ ObjectHasOwn,
24
+ StringPrototypeStartsWith,
25
+ TypeError,
26
+ } = primordials ;
21
27
22
28
/**
23
29
* @param {Deno.CreateHttpClientOptions } options
@@ -26,13 +32,14 @@ const { ObjectDefineProperty } = primordials;
26
32
function createHttpClient ( options ) {
27
33
options . caCerts ??= [ ] ;
28
34
if ( options . proxy ) {
29
- if ( "transport" in options . proxy ) {
35
+ if ( ObjectHasOwn ( options . proxy , "transport" ) ) {
30
36
switch ( options . proxy . transport ) {
31
37
case "http" : {
32
38
const url = options . proxy . url ;
33
39
if (
34
- url . startsWith ( "https:" ) || url . startsWith ( "socks5:" ) ||
35
- url . startsWith ( "socks5h:" )
40
+ StringPrototypeStartsWith ( url , "https:" ) ||
41
+ StringPrototypeStartsWith ( url , "socks5:" ) ||
42
+ StringPrototypeStartsWith ( url , "socks5h:" )
36
43
) {
37
44
throw new TypeError (
38
45
`The url passed into 'proxy.url' has an invalid scheme for this transport.` ,
@@ -44,8 +51,9 @@ function createHttpClient(options) {
44
51
case "https" : {
45
52
const url = options . proxy . url ;
46
53
if (
47
- url . startsWith ( "http:" ) || url . startsWith ( "socks5:" ) ||
48
- url . startsWith ( "socks5h:" )
54
+ StringPrototypeStartsWith ( url , "http:" ) ||
55
+ StringPrototypeStartsWith ( url , "socks5:" ) ||
56
+ StringPrototypeStartsWith ( url , "socks5h:" )
49
57
) {
50
58
throw new TypeError (
51
59
`The url passed into 'proxy.url' has an invalid scheme for this transport.` ,
@@ -56,7 +64,10 @@ function createHttpClient(options) {
56
64
}
57
65
case "socks5" : {
58
66
const url = options . proxy . url ;
59
- if ( ! url . startsWith ( "socks5:" ) || ! url . startsWith ( "socks5h:" ) ) {
67
+ if (
68
+ ! StringPrototypeStartsWith ( url , "socks5:" ) ||
69
+ ! StringPrototypeStartsWith ( url , "socks5h:" )
70
+ ) {
60
71
throw new TypeError (
61
72
`The url passed into 'proxy.url' has an invalid scheme for this transport.` ,
62
73
) ;
@@ -70,7 +81,7 @@ function createHttpClient(options) {
70
81
default : {
71
82
throw new TypeError (
72
83
`Invalid value for 'proxy.transport' option: ${
73
- JSON . stringify ( options . proxy . transport )
84
+ JSONStringify ( options . proxy . transport )
74
85
} `,
75
86
) ;
76
87
}
0 commit comments