MCPcopy
hub / github.com/TarsCloud/TarsGo / ServeHTTP

Method ServeHTTP

tars/httpserver.go:63–81  ·  view source on GitHub ↗

ServeHTTP is the server for the TarsHttpMux.

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

Source from the content-addressed store, hash-verified

61
62// ServeHTTP is the server for the TarsHttpMux.
63func (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
83func (mux *TarsHttpMux) reportHttpStat(st *httpStatInfo) {
84 if mux.cfg == nil || StatReport == nil {

Callers 2

ZipkinHttpMiddlewareFunction · 0.80
BuildHttpHandlerMethod · 0.80

Calls 5

getClientIpMethod · 0.95
reportHttpStatMethod · 0.95
newHttpStatInfoFunction · 0.85
WriteHeaderMethod · 0.80
SetMethod · 0.65

Tested by

no test coverage detected