MCPcopy Index your code
hub / github.com/bettercap/bettercap / fileRoute

Method fileRoute

modules/api_rest/api_rest_controller.go:435–459  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

433}
434
435func (mod *RestAPI) fileRoute(w http.ResponseWriter, r *http.Request) {
436 mod.setSecurityHeaders(w)
437
438 if !mod.checkAuth(r) {
439 mod.setAuthFailed(w, r)
440 return
441 }
442
443 var err error
444
445 fileName := r.URL.Query().Get("name")
446 if fileName, err = fs.Expand(fileName); err != nil {
447 mod.Warning("can't expand %s: %v", fileName, err)
448 http.Error(w, "Bad Request", 400)
449 return
450 }
451
452 if fileName != "" && r.Method == "GET" {
453 mod.readFile(fileName, w, r)
454 } else if fileName != "" && r.Method == "POST" {
455 mod.writeFile(fileName, w, r)
456 } else {
457 http.Error(w, "Bad Request", 400)
458 }
459}

Callers

nothing calls this directly

Calls 8

setSecurityHeadersMethod · 0.95
checkAuthMethod · 0.95
setAuthFailedMethod · 0.95
readFileMethod · 0.95
writeFileMethod · 0.95
GetMethod · 0.45
WarningMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected