Skip to content

Commit

Permalink
Adding support for http1 mode only
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Oct 16, 2021
1 parent 1559e10 commit dae2503
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 3 additions & 1 deletion internal/runner/options.go
Expand Up @@ -31,6 +31,7 @@ type Options struct {
Silent bool
Sandbox bool
MaxFileSize int
HTTP1Only bool
}

// ParseOptions parses the command line options for application
Expand All @@ -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()

Expand Down
1 change: 1 addition & 0 deletions internal/runner/runner.go
Expand Up @@ -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
Expand Down
23 changes: 16 additions & 7 deletions pkg/httpserver/httpserver.go
@@ -1,6 +1,7 @@
package httpserver

import (
"crypto/tls"
"errors"
"net/http"
"os"
Expand All @@ -23,7 +24,8 @@ type Options struct {
BasicAuthReal string
Verbose bool
Sandbox bool
MaxFileSize int // 50Mb
MaxFileSize int
HTTP1Only bool
}

// HTTPServer instance
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit dae2503

Please sign in to comment.