Skip to content

Commit 9f27f6f

Browse files
authored
Merge pull request #56 from projectdiscovery/issue-50-h1-only-mode
Adding support for http1 mode only
2 parents 502ae44 + e0cee73 commit 9f27f6f

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

internal/runner/options.go

+21-20
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,26 @@ import (
1212

1313
// Options of the tool
1414
type Options struct {
15-
ListenAddress string
16-
Folder string
17-
BasicAuth string
18-
username string
19-
password string
20-
Realm string
21-
TLSCertificate string
22-
TLSKey string
23-
TLSDomain string
24-
HTTPS bool
25-
Verbose bool
26-
EnableUpload bool
27-
EnableTCP bool
28-
RulesFile string
29-
TCPWithTLS bool
30-
Version bool
31-
Silent bool
32-
Sandbox bool
33-
MaxFileSize int
15+
ListenAddress string
16+
Folder string
17+
BasicAuth string
18+
username string
19+
password string
20+
Realm string
21+
TLSCertificate string
22+
TLSKey string
23+
TLSDomain string
24+
HTTPS bool
25+
Verbose bool
26+
EnableUpload bool
27+
EnableTCP bool
28+
RulesFile string
29+
TCPWithTLS bool
30+
Version bool
31+
Silent bool
32+
Sandbox bool
33+
MaxFileSize int
34+
HTTP1Only bool
3435
MaxDumpBodySize int
3536
}
3637

@@ -57,9 +58,9 @@ func ParseOptions() *Options {
5758
flag.BoolVar(&options.Version, "version", false, "Show version of the software")
5859
flag.BoolVar(&options.Silent, "silent", false, "Show only results in the output")
5960
flag.BoolVar(&options.Sandbox, "sandbox", false, "Enable sandbox mode")
61+
flag.BoolVar(&options.HTTP1Only, "http1", false, "Enable only HTTP1")
6062
flag.IntVar(&options.MaxFileSize, "max-file-size", 50, "Max Upload File Size")
6163
flag.IntVar(&options.MaxDumpBodySize, "max-dump-body-size", -1, "Max Dump Body Size")
62-
6364
flag.Parse()
6465

6566
// Read the inputs and configure the logging

internal/runner/runner.go

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func New(options *Options) (*Runner, error) {
6060
Verbose: r.options.Verbose,
6161
Sandbox: r.options.Sandbox,
6262
MaxFileSize: r.options.MaxFileSize,
63+
HTTP1Only: r.options.HTTP1Only,
6364
MaxDumpBodySize: unit.ToMb(r.options.MaxDumpBodySize),
6465
})
6566
if err != nil {

pkg/httpserver/httpserver.go

+15-6
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,6 +24,7 @@ type Options struct {
2324
BasicAuthReal string
2425
Verbose bool
2526
Sandbox bool
27+
HTTP1Only bool
2628
MaxFileSize int // 50Mb
2729
MaxDumpBodySize int64
2830
}
@@ -60,9 +62,20 @@ func New(options *Options) (*HTTPServer, error) {
6062
return &h, nil
6163
}
6264

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

6881
// ListenAndServeTLS requests over https
@@ -74,11 +87,7 @@ func (t *HTTPServer) ListenAndServeTLS() error {
7487
if err != nil {
7588
return err
7689
}
77-
httpServer := &http.Server{
78-
Addr: t.options.ListenAddress,
79-
TLSConfig: tlsConfig,
80-
}
81-
httpServer.Handler = t.layers
90+
httpServer := t.makeHTTPServer(tlsConfig)
8291
return httpServer.ListenAndServeTLS("", "")
8392
}
8493
return http.ListenAndServeTLS(t.options.ListenAddress, t.options.Certificate, t.options.CertificateKey, t.layers)

0 commit comments

Comments
 (0)