MCPcopy Create free account
hub / github.com/zalando/skipper / ServeHTTP

Method ServeHTTP

proxy/proxy.go:1754–1903  ·  view source on GitHub ↗

ServeHTTP is the proxy http.Handler implementation

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

Source from the content-addressed store, hash-verified

1752
1753// ServeHTTP is the proxy http.Handler implementation
1754func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
1755
1756 var requestElapsed, responseElapsed time.Duration
1757 requestStopWatch, responseStopWatch := newStopWatch(), newStopWatch()
1758 requestStopWatch.Start()
1759
1760 lw := logging.NewLoggingWriter(w)
1761
1762 p.metrics.IncCounter("incoming." + r.Proto)
1763 var ctx *context
1764
1765 spanOpts := []ot.StartSpanOption{ot.Tags{
1766 SpanKindTag: SpanKindServer,
1767 }}
1768 if wireContext, err := p.tracing.tracer.Extract(ot.HTTPHeaders, ot.HTTPHeadersCarrier(r.Header)); err == nil {
1769 spanOpts = append(spanOpts, ext.RPCServerOption(wireContext))
1770 }
1771 span := p.tracing.tracer.StartSpan(p.tracing.initialOperationName, spanOpts...)
1772
1773 defer func() {
1774 if ctx != nil && ctx.proxySpan != nil {
1775 ctx.proxySpan.Finish()
1776 }
1777 span.Finish()
1778 requestStopWatch.Stop()
1779 responseStopWatch.Stop()
1780
1781 p.metrics.MeasureProxy(requestElapsed+requestStopWatch.Elapsed(), responseElapsed+responseStopWatch.Elapsed())
1782 }()
1783
1784 defer func() {
1785 accessLogEnabled, ok := ctx.stateBag[al.AccessLogEnabledKey].(*al.AccessLogFilter)
1786 if !ok {
1787 if p.accessLogDisabled {
1788 accessLogEnabled = &disabledAccessLog
1789 } else {
1790 accessLogEnabled = &enabledAccessLog
1791 }
1792 }
1793
1794 statusCode := lw.GetCode()
1795
1796 if shouldLog(statusCode, accessLogEnabled) {
1797 authUser, _ := ctx.stateBag[filterslog.AuthUserKey].(string)
1798 entry := &logging.AccessEntry{
1799 Request: r,
1800 ResponseSize: lw.GetBytes(),
1801 StatusCode: statusCode,
1802 RequestTime: ctx.startServe,
1803 Duration: time.Since(ctx.startServe),
1804 AuthUser: authUser,
1805 }
1806
1807 additionalData, _ := ctx.stateBag[al.AccessLogAdditionalDataKey].(map[string]interface{})
1808 if p.accessLogger != nil {
1809 p.accessLogger.LogAccess(entry, additionalData)
1810 }
1811 }

Callers 15

TestTracingSpanNameFunction · 0.45
testLoopbackFunction · 0.45
TestBreakerLeakFunction · 0.45
TestGetRoundtripFunction · 0.45
TestPostRoundtripFunction · 0.45
TestRouteFunction · 0.45
TestFastCgiFunction · 0.45
TestStreamingFunction · 0.45
TestAppliesFiltersFunction · 0.45

Calls 15

GetCodeMethod · 0.95
GetBytesMethod · 0.95
FlushMethod · 0.95
setCommonSpanInfoMethod · 0.95
LoggerMethod · 0.95
doMethod · 0.95
StateBagMethod · 0.95
ResponseControllerMethod · 0.95
errorResponseMethod · 0.95
serveResponseMethod · 0.95
NewLoggingWriterFunction · 0.92
PatchPathFunction · 0.92

Tested by 15

TestTracingSpanNameFunction · 0.36
testLoopbackFunction · 0.36
TestBreakerLeakFunction · 0.36
TestGetRoundtripFunction · 0.36
TestPostRoundtripFunction · 0.36
TestRouteFunction · 0.36
TestFastCgiFunction · 0.36
TestStreamingFunction · 0.36
TestAppliesFiltersFunction · 0.36