-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathengine_params_experimental_options.go
More file actions
108 lines (96 loc) · 3.42 KB
/
engine_params_experimental_options.go
File metadata and controls
108 lines (96 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package cronet
import (
"encoding/json"
"strings"
)
func (p EngineParams) SetExperimentalOption(key string, value any) error {
options := strings.TrimSpace(p.ExperimentalOptions())
experimentalOptions := make(map[string]any)
if options != "" {
if err := json.Unmarshal([]byte(options), &experimentalOptions); err != nil {
return err
}
}
if value == nil {
delete(experimentalOptions, key)
} else {
experimentalOptions[key] = value
}
encoded, err := json.Marshal(experimentalOptions)
if err != nil {
return err
}
p.SetExperimentalOptions(string(encoded))
return nil
}
func (p EngineParams) SetAsyncDNS(enable bool) error {
if !enable {
return p.SetExperimentalOption("AsyncDNS", nil)
}
return p.SetExperimentalOption("AsyncDNS", map[string]any{
"enable": true,
})
}
// SetDNSServerOverride configures Cronet's built-in DNS client to exclusively use the
// provided nameserver addresses.
//
// The nameserver entries must be IP literals, in "ip:port" form (IPv6 in "[ip]:port"
// form). Passing an empty slice disables the override.
func (p EngineParams) SetDNSServerOverride(nameservers []string) error {
if len(nameservers) == 0 {
return p.SetExperimentalOption("DnsServerOverride", nil)
}
return p.SetExperimentalOption("DnsServerOverride", map[string]any{
"nameservers": nameservers,
})
}
// SetHostResolverRules sets rules to override DNS resolution.
// Format: "MAP hostname ip" or "MAP *.example.com ip" or "EXCLUDE hostname".
// Multiple rules can be separated by commas: "MAP foo 1.2.3.4, MAP bar 5.6.7.8".
// See net/dns/mapped_host_resolver.h for full format.
func (p EngineParams) SetHostResolverRules(rules string) error {
if rules == "" {
return p.SetExperimentalOption("HostResolverRules", nil)
}
return p.SetExperimentalOption("HostResolverRules", map[string]any{
"host_resolver_rules": rules,
})
}
// SetUseDnsHttpsSvcb enables or disables DNS HTTPS SVCB record lookups.
// When enabled, Chromium will query DNS for HTTPS records (type 65) which can
// contain ECH (Encrypted Client Hello) configurations and ALPN hints.
// This is required for ECH support.
func (p EngineParams) SetUseDnsHttpsSvcb(enable bool) error {
return p.SetExperimentalOption("UseDnsHttpsSvcb", map[string]any{
"enable": enable,
})
}
func (p EngineParams) SetHTTP2Options(sessionMaxReceiveWindowSize, initialWindowSize uint64) error {
return p.SetExperimentalOption("HTTP2Options", map[string]any{
"session_max_recv_window_size": sessionMaxReceiveWindowSize,
"initial_window_size": initialWindowSize,
})
}
func (p EngineParams) SetQUICOptions(connectionOptions string, initialStreamRecvWindowSize, initialSessionRecvWindowSize uint64) error {
options := map[string]any{}
if connectionOptions != "" {
options["connection_options"] = connectionOptions
}
if initialStreamRecvWindowSize > 0 {
options["initial_stream_recv_window_size"] = initialStreamRecvWindowSize
}
if initialSessionRecvWindowSize > 0 {
options["initial_session_recv_window_size"] = initialSessionRecvWindowSize
}
if len(options) == 0 {
return p.SetExperimentalOption("QUIC", nil)
}
return p.SetExperimentalOption("QUIC", options)
}
func (p EngineParams) SetSocketPoolOptions(maxPerPool, maxPerProxyChain, maxPerGroup int) error {
return p.SetExperimentalOption("SocketPoolOptions", map[string]any{
"max_sockets_per_pool": maxPerPool,
"max_sockets_per_proxy_chain": maxPerProxyChain,
"max_sockets_per_group": maxPerGroup,
})
}