11package httpserver
22
33import (
4+ "crypto/tls"
45 "errors"
56 "net/http"
67 "os"
@@ -23,7 +24,8 @@ type Options struct {
2324 BasicAuthReal string
2425 Verbose bool
2526 Sandbox bool
26- MaxFileSize int // 50Mb
27+ MaxFileSize int
28+ HTTP1Only bool
2729}
2830
2931// HTTPServer instance
@@ -59,9 +61,20 @@ func New(options *Options) (*HTTPServer, error) {
5961 return & h , nil
6062}
6163
64+ func (t * HTTPServer ) makeHTTPServer (tlsConfig * tls.Config ) * http.Server {
65+ httpServer := & http.Server {Addr : t .options .ListenAddress }
66+ if t .options .HTTP1Only {
67+ httpServer .TLSNextProto = make (map [string ]func (* http.Server , * tls.Conn , http.Handler ))
68+ }
69+ httpServer .TLSConfig = tlsConfig
70+ httpServer .Handler = t .layers
71+ return httpServer
72+ }
73+
6274// ListenAndServe requests over http
6375func (t * HTTPServer ) ListenAndServe () error {
64- return http .ListenAndServe (t .options .ListenAddress , t .layers )
76+ httpServer := t .makeHTTPServer (nil )
77+ return httpServer .ListenAndServe ()
6578}
6679
6780// ListenAndServeTLS requests over https
@@ -73,11 +86,7 @@ func (t *HTTPServer) ListenAndServeTLS() error {
7386 if err != nil {
7487 return err
7588 }
76- httpServer := & http.Server {
77- Addr : t .options .ListenAddress ,
78- TLSConfig : tlsConfig ,
79- }
80- httpServer .Handler = t .layers
89+ httpServer := t .makeHTTPServer (tlsConfig )
8190 return httpServer .ListenAndServeTLS ("" , "" )
8291 }
8392 return http .ListenAndServeTLS (t .options .ListenAddress , t .options .Certificate , t .options .CertificateKey , t .layers )
0 commit comments