Skip to content

Commit dae2503

Browse files
committed
Adding support for http1 mode only
1 parent 1559e10 commit dae2503

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

internal/runner/options.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Options struct {
3131
Silent bool
3232
Sandbox bool
3333
MaxFileSize int
34+
HTTP1Only bool
3435
}
3536

3637
// ParseOptions parses the command line options for application
@@ -56,7 +57,8 @@ func ParseOptions() *Options {
5657
flag.BoolVar(&options.Version, "version", false, "Show version of the software")
5758
flag.BoolVar(&options.Silent, "silent", false, "Show only results in the output")
5859
flag.BoolVar(&options.Sandbox, "sandbox", false, "Enable sandbox mode")
59-
flag.IntVar(&options.MaxFileSize, "max-file-size", 50, "Max Upload File Size")
60+
flag.IntVar(&options.MaxFileSize, "max-file-size", 50, "Max Upload File Size in Mb")
61+
flag.BoolVar(&options.HTTP1Only, "http1", false, "Enable only HTTP1")
6062

6163
flag.Parse()
6264

internal/runner/runner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func New(options *Options) (*Runner, error) {
5959
Verbose: r.options.Verbose,
6060
Sandbox: r.options.Sandbox,
6161
MaxFileSize: r.options.MaxFileSize,
62+
HTTP1Only: r.options.HTTP1Only,
6263
})
6364
if err != nil {
6465
return nil, err

pkg/httpserver/httpserver.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package httpserver
22

33
import (
4+
"crypto/tls"
45
"errors"
56
"net/http"
67
"os"
@@ -23,7 +24,8 @@ type Options struct {
2324
BasicAuthReal string
2425
Verbose bool
2526
Sandbox bool
26-
MaxFileSize int // 50Mb
27+
MaxFileSize int
28+
HTTP1Only bool
2729
}
2830

2931
// HTTPServer instance
@@ -59,9 +61,20 @@ func New(options *Options) (*HTTPServer, error) {
5961
return &h, nil
6062
}
6163

64+
func (t *HTTPServer) makeHTTPServer(tlsConfig *tls.Config) *http.Server {
65+
httpServer := &http.Server{Addr: t.options.ListenAddress}
66+
if t.options.HTTP1Only {
67+
httpServer.TLSNextProto = make(map[string]func(*http.Server, *tls.Conn, http.Handler))
68+
}
69+
httpServer.TLSConfig = tlsConfig
70+
httpServer.Handler = t.layers
71+
return httpServer
72+
}
73+
6274
// ListenAndServe requests over http
6375
func (t *HTTPServer) ListenAndServe() error {
64-
return http.ListenAndServe(t.options.ListenAddress, t.layers)
76+
httpServer := t.makeHTTPServer(nil)
77+
return httpServer.ListenAndServe()
6578
}
6679

6780
// ListenAndServeTLS requests over https
@@ -73,11 +86,7 @@ func (t *HTTPServer) ListenAndServeTLS() error {
7386
if err != nil {
7487
return err
7588
}
76-
httpServer := &http.Server{
77-
Addr: t.options.ListenAddress,
78-
TLSConfig: tlsConfig,
79-
}
80-
httpServer.Handler = t.layers
89+
httpServer := t.makeHTTPServer(tlsConfig)
8190
return httpServer.ListenAndServeTLS("", "")
8291
}
8392
return http.ListenAndServeTLS(t.options.ListenAddress, t.options.Certificate, t.options.CertificateKey, t.layers)

0 commit comments

Comments
 (0)