MCPcopy
hub / github.com/nirui/sshwifty / ServeHTTP

Method ServeHTTP

application/controller/controller.go:46–117  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

44}
45
46func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
47 var err error
48
49 clientLogger := h.logger.Context("Client (%s)", r.RemoteAddr)
50
51 if len(h.commonCfg.HostName) > 0 {
52 hostPort := r.Host
53
54 if len(hostPort) <= 0 {
55 hostPort = r.URL.Host
56 }
57
58 if h.commonCfg.HostName != hostPort &&
59 !strings.HasPrefix(hostPort, h.hostNameChecker) {
60 clientLogger.Warning("Request invalid host \"%s\", deined",
61 r.Host)
62
63 serveFailure(
64 NewError(http.StatusForbidden, "Invalid host"), w, r, h.logger)
65
66 return
67 }
68 }
69
70 w.Header().Add("Date", time.Now().UTC().Format(time.RFC1123))
71
72 switch r.URL.Path {
73 case "/":
74 err = serveController(h.homeCtl, w, r, clientLogger)
75
76 case "/socket":
77 err = serveController(h.socketCtl, w, r, clientLogger)
78
79 case "/robots.txt":
80 fallthrough
81 case "/favicon.ico":
82 fallthrough
83 case "/README.md":
84 fallthrough
85 case "/LICENSE.md":
86 fallthrough
87 case "/DEPENDENCIES.md":
88 err = serveStaticData(r.URL.Path[1:], w, r, clientLogger)
89
90 default:
91 if strings.HasPrefix(r.URL.Path, "/assets/") {
92 err = serveStaticData(r.URL.Path[8:], w, r, clientLogger)
93 } else {
94 err = ErrNotFound
95 }
96 }
97
98 if err == nil {
99 clientLogger.Info("Request completed: %s", r.URL.String())
100
101 return
102 }
103

Callers

nothing calls this directly

Calls 9

serveFailureFunction · 0.85
NewErrorFunction · 0.85
serveControllerFunction · 0.85
serveStaticDataFunction · 0.85
ContextMethod · 0.65
WarningMethod · 0.65
InfoMethod · 0.65
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected