-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.go
More file actions
41 lines (36 loc) · 964 Bytes
/
Copy pathhttp.go
File metadata and controls
41 lines (36 loc) · 964 Bytes
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
package singproxy
import (
"errors"
"fmt"
"net/url"
"strings"
"github.com/sagernet/sing-box/option"
)
func parseHTTP(out *option.HTTPOutboundOptions, u *url.URL) error {
host := u.Hostname()
if host == "" {
return errors.New("http proxy host is empty")
}
port, err := parsePort(u.Port())
if err != nil {
return fmt.Errorf("invalid http port: %w", err)
}
out.ServerOptions = option.ServerOptions{Server: host, ServerPort: port}
out.Path = u.Path
if u.User != nil {
username, password := parseAuth(u.User.String())
out.Username = username
out.Password = password
}
params := u.Query()
parseTLS(params, &out.OutboundTLSOptionsContainer, host)
if strings.EqualFold(u.Scheme, "https") || strings.EqualFold(u.Scheme, "http2") {
if out.TLS == nil {
out.TLS = &option.OutboundTLSOptions{Enabled: true, ServerName: host}
}
if strings.EqualFold(u.Scheme, "http2") {
out.TLS.ALPN = append(out.TLS.ALPN, "h2")
}
}
return nil
}