MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / ServeHTTP

Method ServeHTTP

pkg/server/handler.go:86–120  ·  view source on GitHub ↗
(w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

84}
85
86func (d director) ServeHTTP(w http.ResponseWriter, req *http.Request) {
87 path := req.URL.Path
88 req.Header.Add(api.AppNameKey, d.name)
89 // check to see if our webservices want to claim this path
90 for _, ws := range d.goRestfulContainer.RegisteredWebServices() {
91 switch {
92 case ws.RootPath() == "/apis":
93 // if we are exactly /apis or /apis/, then we need special handling in loop.
94 // normally these are passed to the nonGoRestfulMux, but if discovery is enabled, it will go directly.
95 // We can't rely on a prefix match since /apis matches everything (see the big comment on Director above)
96 if path == "/apis" || path == "/apis/" {
97 logs.NewLogger().V(10).WithField(api.HeaderXRequestID, req.Header.Get(api.HeaderXRequestID)).WithField(api.AppNameKey, d.name).Debugf("[msg:%s %q satisfied by gorestful with webservice %v]", req.Method, path, ws.RootPath())
98 // logs.Debugf("[%s:%s][%s:%s][msg:%s %q satisfied by gorestful with webservice %v]", api.HeaderXRequestID, req.Header.Get(api.HeaderXRequestID), api.AppNameKey, d.name, req.Method, path, ws.RootPath())
99 // don't use servemux here because gorestful servemuxes get messed up when removing webservices
100 // TODO fix gorestful, remove TPRs, or stop using gorestful
101 d.goRestfulContainer.Dispatch(w, req)
102 return
103 }
104
105 case strings.HasPrefix(path, ws.RootPath()):
106 // ensure an exact match or a path boundary match
107 if len(path) == len(ws.RootPath()) || path[len(ws.RootPath())] == '/' {
108 logs.NewLogger().V(10).WithField(api.HeaderXRequestID, req.Header.Get(api.HeaderXRequestID)).WithField(api.AppNameKey, d.name).Debugf("[msg:%s %q satisfied by gorestful with webservice %v]", req.Method, path, ws.RootPath())
109 // don't use servemux here because gorestful servemuxes get messed up when removing webservices
110 // TODO fix gorestful, remove TPRs, or stop using gorestful
111 d.goRestfulContainer.Dispatch(w, req)
112 return
113 }
114 }
115 }
116
117 // if we didn't find a match, then we just skip gorestful altogether
118 logs.V(8).Infof("%v: %v %q satisfied by nonGoRestful", d.name, req.Method, path)
119 d.nonGoRestfulMux.ServeHTTP(w, req)
120}
121
122// ServeHTTP makes it an http.Handler
123func (s *ServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

Callers 1

ServeHTTPMethod · 0.45

Calls 8

NewLoggerFunction · 0.92
VFunction · 0.92
DebugfMethod · 0.80
WithFieldMethod · 0.80
VMethod · 0.80
InfofMethod · 0.80
GetMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected