Skip to content

Commit aec2de9

Browse files
committed
[+] Listen And Serve TLS [+]
1 parent 672bedb commit aec2de9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pkg/httpserver/httpserver.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package httpserver
22

33
import (
44
"net/http"
5+
6+
"github.com/projectdiscovery/sslcert"
57
)
68

79
type Options struct {
@@ -39,3 +41,21 @@ func New(options *Options) (*HTTPServer, error) {
3941
func (t *HTTPServer) ListenAndServe() error {
4042
return http.ListenAndServe(t.options.ListenAddress, t.layers)
4143
}
44+
45+
func (t *HTTPServer) ListenAndServeTLS() error {
46+
if t.options.Certificate == "" || t.options.CertificateKey == "" {
47+
tlsOptions := sslcert.DefaultOptions
48+
tlsOptions.Host = t.options.CertificateDomain
49+
tlsConfig, err := sslcert.NewTLSConfig(tlsOptions)
50+
if err != nil {
51+
return err
52+
}
53+
httpServer := &http.Server{
54+
Addr: t.options.ListenAddress,
55+
TLSConfig: tlsConfig,
56+
}
57+
httpServer.Handler = t.layers
58+
return httpServer.ListenAndServeTLS("", "")
59+
}
60+
return http.ListenAndServeTLS(t.options.ListenAddress, t.options.Certificate, t.options.CertificateKey, t.layers)
61+
}

0 commit comments

Comments
 (0)