ServeHTTP is the server for the TarsHttpMux.
(w http.ResponseWriter, r *http.Request)
| 61 | |
| 62 | // ServeHTTP is the server for the TarsHttpMux. |
| 63 | func (mux *TarsHttpMux) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| 64 | if r.RequestURI == "*" { |
| 65 | if r.ProtoAtLeast(1, 1) { |
| 66 | w.Header().Set("Connection", "close") |
| 67 | } |
| 68 | w.WriteHeader(http.StatusBadRequest) |
| 69 | return |
| 70 | } |
| 71 | tw := &TarsResponseWriter{w, 0} |
| 72 | h, pattern := mux.Handler(r) |
| 73 | startTime := time.Now().UnixNano() / 1e6 |
| 74 | h.ServeHTTP(tw, r) |
| 75 | costTime := time.Now().UnixNano()/1e6 - startTime |
| 76 | if pattern == "" { |
| 77 | pattern = "/" |
| 78 | } |
| 79 | st := newHttpStatInfo(mux.getClientIp(r), pattern, tw.StatusCode, costTime) |
| 80 | go mux.reportHttpStat(st) |
| 81 | } |
| 82 | |
| 83 | func (mux *TarsHttpMux) reportHttpStat(st *httpStatInfo) { |
| 84 | if mux.cfg == nil || StatReport == nil { |
no test coverage detected