MCPcopy Create free account
hub / github.com/go-dev-frame/sponge / ServeHTTP

Method ServeHTTP

pkg/proxykit/proxy.go:25–40  ·  view source on GitHub ↗

ServeHTTP handles incoming HTTP requests and forwards them to the backend selected by the load balancer.

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

Source from the content-addressed store, hash-verified

23// ServeHTTP handles incoming HTTP requests and forwards them to the backend
24// selected by the load balancer.
25func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
26 // Select a healthy backend according to the load balancing strategy.
27 backend, err := p.balancer.Next(r)
28 if err != nil {
29 log.Printf("[Proxy] error selecting backend: %v", err)
30 http.Error(w, "service not available", http.StatusServiceUnavailable)
31 return
32 }
33
34 // Increase the active connection count, and ensure it is decremented
35 // when the request completes.
36 backend.IncrementActiveConns()
37 defer backend.DecrementActiveConns()
38
39 backend.proxy.ServeHTTP(w, r)
40}

Calls 5

PrintfMethod · 0.80
IncrementActiveConnsMethod · 0.80
DecrementActiveConnsMethod · 0.80
NextMethod · 0.65
ErrorMethod · 0.65