Skip to content

Commit e47330a

Browse files
committed
CLI: nullable ALPN list
1 parent 8c59729 commit e47330a

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

main.go

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,40 @@ func arg_fail(msg string) {
6767
os.Exit(2)
6868
}
6969

70-
type CSVArg []string
71-
72-
func (a *CSVArg) Set(s string) error {
73-
*a = strings.Split(s, ",")
74-
return nil
70+
type CSVArg struct {
71+
values []string
7572
}
7673

7774
func (a *CSVArg) String() string {
78-
if a == nil {
79-
return "<nil>"
80-
}
81-
if *a == nil {
82-
return "<empty>"
75+
if len(a.values) == 0 {
76+
return ""
8377
}
84-
return strings.Join(*a, ",")
78+
buf := new(bytes.Buffer)
79+
wr := csv.NewWriter(buf)
80+
wr.Write(a.values)
81+
wr.Flush()
82+
return strings.TrimRight(buf.String(), "\n")
8583
}
8684

87-
func (a *CSVArg) Value() []string {
88-
return []string(*a)
85+
func (a *CSVArg) Set(line string) error {
86+
if line == "" {
87+
a.values = nil
88+
return nil
89+
}
90+
rd := csv.NewReader(strings.NewReader(line))
91+
rd.FieldsPerRecord = -1
92+
rd.TrimLeadingSpace = true
93+
rd.ReuseRecord = true
94+
values, err := rd.Read()
95+
if err == io.EOF {
96+
a.values = nil
97+
return nil
98+
}
99+
if err != nil {
100+
return fmt.Errorf("unable to parse comma-separated argument: %w", err)
101+
}
102+
a.values = values
103+
return nil
89104
}
90105

91106
type PrefixList []netip.Prefix
@@ -295,6 +310,8 @@ type CLIArgs struct {
295310
userIPHints bool
296311
minTLSVersion TLSVersionArg
297312
maxTLSVersion TLSVersionArg
313+
tlsALPNEnabled bool
314+
tlsALPNProtos CSVArg
298315
bwLimit uint64
299316
bwBurst int64
300317
bwBuckets uint
@@ -420,6 +437,8 @@ func parse_args() *CLIArgs {
420437
flag.BoolVar(&args.userIPHints, "user-ip-hints", false, "allow IP hints to be specified by user in X-Src-IP-Hints header")
421438
flag.Var(&args.minTLSVersion, "min-tls-version", "minimum TLS version accepted by server")
422439
flag.Var(&args.maxTLSVersion, "max-tls-version", "maximum TLS version accepted by server")
440+
flag.BoolVar(&args.tlsALPNEnabled, "tls-alpn-enabled", true, "enable application protocol negotiation with TLS ALPN extension")
441+
flag.Var(&args.tlsALPNProtos, "tls-alpn-protos", "comma-separated values (RFC 4180) of enabled ALPN identities")
423442
flag.Uint64Var(&args.bwLimit, "bw-limit", 0, "per-user bandwidth limit in bytes per second")
424443
flag.Int64Var(&args.bwBurst, "bw-limit-burst", 0, "allowed burst size for bandwidth limit, how many \"tokens\" can fit into leaky bucket")
425444
flag.UintVar(&args.bwBuckets, "bw-limit-buckets", 1024*1024, "number of buckets of bandwidth limit")
@@ -733,8 +752,8 @@ func run() int {
733752
Client: &acme.Client{DirectoryURL: args.autocertACME},
734753
Email: args.autocertEmail,
735754
}
736-
if args.autocertWhitelist.Value() != nil {
737-
m.HostPolicy = autocert.HostWhitelist(args.autocertWhitelist.Value()...)
755+
if args.autocertWhitelist.values != nil {
756+
m.HostPolicy = autocert.HostWhitelist(args.autocertWhitelist.values...)
738757
}
739758
if args.autocertHTTP != "" {
740759
go func() {

0 commit comments

Comments
 (0)