mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 05:23:19 -07:00
fix: fixed a bug which caused the http.server module to crash if restarted in the same session
This commit is contained in:
parent
3926f52f2d
commit
67160a97d3
1 changed files with 9 additions and 8 deletions
|
@ -77,13 +77,6 @@ func (httpd *HttpServer) Author() string {
|
||||||
return "Simone Margaritelli <evilsocket@protonmail.com>"
|
return "Simone Margaritelli <evilsocket@protonmail.com>"
|
||||||
}
|
}
|
||||||
|
|
||||||
func wrapHandler(h http.Handler) http.Handler {
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
log.Info("(%s) %s %s %s%s", core.Green("httpd"), core.Bold(strings.Split(r.RemoteAddr, ":")[0]), r.Method, r.Host, r.URL.Path)
|
|
||||||
h.ServeHTTP(w, r)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (httpd *HttpServer) isTLS() bool {
|
func (httpd *HttpServer) isTLS() bool {
|
||||||
return httpd.certFile != "" && httpd.keyFile != ""
|
return httpd.certFile != "" && httpd.keyFile != ""
|
||||||
}
|
}
|
||||||
|
@ -100,7 +93,15 @@ func (httpd *HttpServer) Configure() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
http.Handle("/", wrapHandler(http.FileServer(http.Dir(path))))
|
router := http.NewServeMux()
|
||||||
|
fileServer := http.FileServer(http.Dir(path))
|
||||||
|
|
||||||
|
router.HandleFunc("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
log.Info("(%s) %s %s %s%s", core.Green("httpd"), core.Bold(strings.Split(r.RemoteAddr, ":")[0]), r.Method, r.Host, r.URL.Path)
|
||||||
|
fileServer.ServeHTTP(w, r)
|
||||||
|
}))
|
||||||
|
|
||||||
|
httpd.server.Handler = router
|
||||||
|
|
||||||
if err, address = httpd.StringParam("http.server.address"); err != nil {
|
if err, address = httpd.StringParam("http.server.address"); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue