Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions internal/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,26 @@ import (

// Options of the tool
type Options struct {
ListenAddress string
Folder string
BasicAuth string
username string
password string
Realm string
TLSCertificate string
TLSKey string
TLSDomain string
HTTPS bool
Verbose bool
EnableUpload bool
EnableTCP bool
RulesFile string
TCPWithTLS bool
Version bool
Silent bool
Sandbox bool
MaxFileSize int
ListenAddress string
Folder string
BasicAuth string
username string
password string
Realm string
TLSCertificate string
TLSKey string
TLSDomain string
HTTPS bool
Verbose bool
EnableUpload bool
EnableTCP bool
RulesFile string
TCPWithTLS bool
Version bool
Silent bool
Sandbox bool
MaxFileSize int
HTTP1Only bool
MaxDumpBodySize int
}

Expand All @@ -57,9 +58,9 @@ 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.BoolVar(&options.HTTP1Only, "http1", false, "Enable only HTTP1")
flag.IntVar(&options.MaxFileSize, "max-file-size", 50, "Max Upload File Size")
flag.IntVar(&options.MaxDumpBodySize, "max-dump-body-size", -1, "Max Dump Body Size")

flag.Parse()

// Read the inputs and configure the logging
Expand Down
1 change: 1 addition & 0 deletions internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func New(options *Options) (*Runner, error) {
Verbose: r.options.Verbose,
Sandbox: r.options.Sandbox,
MaxFileSize: r.options.MaxFileSize,
HTTP1Only: r.options.HTTP1Only,
MaxDumpBodySize: unit.ToMb(r.options.MaxDumpBodySize),
})
if err != nil {
Expand Down
21 changes: 15 additions & 6 deletions pkg/httpserver/httpserver.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package httpserver

import (
"crypto/tls"
"errors"
"net/http"
"os"
Expand All @@ -23,6 +24,7 @@ type Options struct {
BasicAuthReal string
Verbose bool
Sandbox bool
HTTP1Only bool
MaxFileSize int // 50Mb
MaxDumpBodySize int64
}
Expand Down Expand Up @@ -60,9 +62,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 @@ -74,11 +87,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