MCPcopy
hub / github.com/cubefs/cubefs / expectMiddleware

Method expectMiddleware

objectnode/api_middleware.go:221–237  ·  view source on GitHub ↗

Http's Expect header is a special header. When nginx is used as the reverse proxy in the front end of ObjectNode, nginx will process the Expect header information in advance, send the http status code 100 to the client, and will not forward this header information to ObjectNode. At this time, if the

(next http.Handler)

Source from the content-addressed store, hash-verified

219// the original value of Expect to the ObjectNode through X-Forwarded-Expect. ObjectNode only
220// needs to use the value of X-Forwarded-Expect.
221func (o *ObjectNode) expectMiddleware(next http.Handler) http.Handler {
222 var handlerFunc http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
223 defer func() {
224 // panic recover and response specific status to client
225 p := recover()
226 if p != nil {
227 log.LogErrorf("panic(%v): requestID(%v) stack(%v)", p, GetRequestID(r), string(debug.Stack()))
228 w.WriteHeader(StatusServerPanic)
229 }
230 }()
231 if forwarded, origin := r.Header.Get(XForwardedExpect), r.Header.Get(Expect); forwarded != "" && origin == "" {
232 r.Header.Set(Expect, forwarded)
233 }
234 next.ServeHTTP(w, r)
235 }
236 return handlerFunc
237}
238
239// CORSMiddleware returns a middleware handler to support CORS request.
240// This handler will write following header into response:

Callers

nothing calls this directly

Calls 6

LogErrorfFunction · 0.92
GetRequestIDFunction · 0.85
GetMethod · 0.65
SetMethod · 0.65
WriteHeaderMethod · 0.45
ServeHTTPMethod · 0.45

Tested by

no test coverage detected