ServeHTTP make sure request can be handled correctly
(w http.ResponseWriter, req *http.Request)
| 165 | |
| 166 | // ServeHTTP make sure request can be handled correctly |
| 167 | func (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 |
| 203 | func (server *HttpServer) IsOffline() bool { |
nothing calls this directly
no test coverage detected