MCPcopy Create free account
hub / github.com/devfeel/dotweb / ServeHTTP

Method ServeHTTP

server.go:167–200  ·  view source on GitHub ↗

ServeHTTP make sure request can be handled correctly

(w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

165
166// ServeHTTP make sure request can be handled correctly
167func (server *HttpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
168 server.StateInfo().AddCurrentRequest(1)
169 defer server.StateInfo().SubCurrentRequest(1)
170
171 // special handling for websocket and debugging
172 if checkIsWebSocketRequest(req) {
173 http.DefaultServeMux.ServeHTTP(w, req)
174 server.StateInfo().AddRequestCount(req.URL.Path, defaultHttpCode, 1)
175 } else {
176 // setup header
177 w.Header().Set(HeaderServer, DefaultServerName)
178 httpCtx := prepareHttpContext(server, w, req)
179 // process OnBeginRequest of modules
180 for _, module := range server.Modules {
181 if module.OnBeginRequest != nil {
182 module.OnBeginRequest(httpCtx)
183 }
184 }
185
186 if !httpCtx.IsEnd() {
187 server.Router().ServeHTTP(httpCtx)
188 }
189
190 // process OnEndRequest of modules
191 for _, module := range server.Modules {
192 if module.OnEndRequest != nil {
193 module.OnEndRequest(httpCtx)
194 }
195 }
196 server.StateInfo().AddRequestCount(httpCtx.Request().Path(), httpCtx.Response().HttpCode(), 1)
197
198 releaseHttpContext(server, httpCtx)
199 }
200}
201
202// IsOffline check server is set offline state
203func (server *HttpServer) IsOffline() bool {

Callers

nothing calls this directly

Calls 15

StateInfoMethod · 0.95
RouterMethod · 0.95
checkIsWebSocketRequestFunction · 0.85
prepareHttpContextFunction · 0.85
releaseHttpContextFunction · 0.85
AddCurrentRequestMethod · 0.80
SubCurrentRequestMethod · 0.80
AddRequestCountMethod · 0.80
HttpCodeMethod · 0.80
ServeHTTPMethod · 0.65
SetMethod · 0.65
IsEndMethod · 0.65

Tested by

no test coverage detected