diff --git a/internal/runner/options.go b/internal/runner/options.go index a5869d6..6094c7a 100644 --- a/internal/runner/options.go +++ b/internal/runner/options.go @@ -31,6 +31,7 @@ type Options struct { Silent bool Sandbox bool MaxFileSize int + HTTP1Only bool } // ParseOptions parses the command line options for application @@ -56,7 +57,8 @@ func ParseOptions() *Options { flag.BoolVar(&options.Version, "version", false, "Show version of the software") flag.BoolVar(&options.Silent, "silent", false, "Show only results in the output") flag.BoolVar(&options.Sandbox, "sandbox", false, "Enable sandbox mode") - flag.IntVar(&options.MaxFileSize, "max-file-size", 50, "Max Upload File Size") + flag.IntVar(&options.MaxFileSize, "max-file-size", 50, "Max Upload File Size in Mb") + flag.BoolVar(&options.HTTP1Only, "http1", false, "Enable only HTTP1") flag.Parse() diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 5806044..88fe753 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -59,6 +59,7 @@ func New(options *Options) (*Runner, error) { Verbose: r.options.Verbose, Sandbox: r.options.Sandbox, MaxFileSize: r.options.MaxFileSize, + HTTP1Only: r.options.HTTP1Only, }) if err != nil { return nil, err diff --git a/pkg/httpserver/httpserver.go b/pkg/httpserver/httpserver.go index 72da466..be44567 100644 --- a/pkg/httpserver/httpserver.go +++ b/pkg/httpserver/httpserver.go @@ -1,6 +1,7 @@ package httpserver import ( + "crypto/tls" "errors" "net/http" "os" @@ -23,7 +24,8 @@ type Options struct { BasicAuthReal string Verbose bool Sandbox bool - MaxFileSize int // 50Mb + MaxFileSize int + HTTP1Only bool } // HTTPServer instance @@ -59,9 +61,20 @@ func New(options *Options) (*HTTPServer, error) { return &h, nil } +func (t *HTTPServer) makeHTTPServer(tlsConfig *tls.Config) *http.Server { + httpServer := &http.Server{Addr: t.options.ListenAddress} + if t.options.HTTP1Only { + httpServer.TLSNextProto = make(map[string]func(*http.Server, *tls.Conn, http.Handler)) + } + httpServer.TLSConfig = tlsConfig + httpServer.Handler = t.layers + return httpServer +} + // ListenAndServe requests over http func (t *HTTPServer) ListenAndServe() error { - return http.ListenAndServe(t.options.ListenAddress, t.layers) + httpServer := t.makeHTTPServer(nil) + return httpServer.ListenAndServe() } // ListenAndServeTLS requests over https @@ -73,11 +86,7 @@ func (t *HTTPServer) ListenAndServeTLS() error { if err != nil { return err } - httpServer := &http.Server{ - Addr: t.options.ListenAddress, - TLSConfig: tlsConfig, - } - httpServer.Handler = t.layers + httpServer := t.makeHTTPServer(tlsConfig) return httpServer.ListenAndServeTLS("", "") } return http.ListenAndServeTLS(t.options.ListenAddress, t.options.Certificate, t.options.CertificateKey, t.layers)