Skip to content

Commit

Permalink
Merge pull request projectdiscovery#56 from projectdiscovery/issue-50…
Browse files Browse the repository at this point in the history
…-h1-only-mode

Adding support for http1 mode only
  • Loading branch information
ehsandeep committed Oct 30, 2021
2 parents 502ae44 + e0cee73 commit 9f27f6f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
41 changes: 21 additions & 20 deletions internal/runner/options.go
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
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
@@ -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

0 comments on commit 9f27f6f

Please sign in to comment.