MCPcopy
hub / github.com/bettercap/bettercap / Configure

Method Configure

modules/http_server/http_server.go:67–105  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65}
66
67func (mod *HttpServer) Configure() error {
68 var err error
69 var path string
70 var address string
71 var port int
72
73 if mod.Running() {
74 return session.ErrAlreadyStarted(mod.Name())
75 }
76
77 if err, path = mod.StringParam("http.server.path"); err != nil {
78 return err
79 }
80
81 router := http.NewServeMux()
82 fileServer := http.FileServer(http.Dir(path))
83
84 router.HandleFunc("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
85 mod.Debug("%s %s %s%s", tui.Bold(strings.Split(r.RemoteAddr, ":")[0]), r.Method, r.Host, r.URL.Path)
86 if r.URL.Path == "/proxy.pac" || r.URL.Path == "/wpad.dat" {
87 w.Header().Set("Content-Type", "application/x-ns-proxy-autoconfig")
88 }
89 fileServer.ServeHTTP(w, r)
90 }))
91
92 mod.server.Handler = router
93
94 if err, address = mod.StringParam("http.server.address"); err != nil {
95 return err
96 }
97
98 if err, port = mod.IntParam("http.server.port"); err != nil {
99 return err
100 }
101
102 mod.server.Addr = fmt.Sprintf("%s:%d", address, port)
103
104 return nil
105}
106
107func (mod *HttpServer) Start() error {
108 if err := mod.Configure(); err != nil {

Callers 1

StartMethod · 0.95

Calls 8

NameMethod · 0.95
ErrAlreadyStartedFunction · 0.92
StringParamMethod · 0.80
HeaderMethod · 0.80
IntParamMethod · 0.80
RunningMethod · 0.65
DebugMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected