本文整理汇总了Golang中github.com/cloudfoundry/gorouter/access_log.AccessLogRecord.Response方法的典型用法代码示例。如果您正苦于以下问题:Golang AccessLogRecord.Response方法的具体用法?Golang AccessLogRecord.Response怎么用?Golang AccessLogRecord.Response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/gorouter/access_log.AccessLogRecord
的用法示例。
在下文中一共展示了AccessLogRecord.Response方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ServeHTTP
func (proxy *Proxy) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) {
startedAt := time.Now()
originalURL := request.URL
request.URL = &url.URL{Host: originalURL.Host, Opaque: request.RequestURI}
handler := NewRequestHandler(request, responseWriter)
accessLog := access_log.AccessLogRecord{
Request: request,
StartedAt: startedAt,
}
defer func() {
proxy.AccessLogger.Log(accessLog)
}()
if !isProtocolSupported(request) {
handler.HandleUnsupportedProtocol()
return
}
if isLoadBalancerHeartbeat(request) {
handler.HandleHeartbeat()
return
}
routeEndpoint, found := proxy.Lookup(request)
if !found {
proxy.Varz.CaptureBadRequest(request)
handler.HandleMissingRoute()
return
}
handler.logger.Set("RouteEndpoint", routeEndpoint.ToLogData())
accessLog.RouteEndpoint = routeEndpoint
proxy.Varz.CaptureRoutingRequest(routeEndpoint, handler.request)
if isTcpUpgrade(request) {
handler.HandleTcpRequest(routeEndpoint)
return
}
if isWebSocketUpgrade(request) {
handler.HandleWebSocketRequest(routeEndpoint)
return
}
endpointResponse, err := handler.HandleHttpRequest(proxy.Transport, routeEndpoint)
latency := time.Since(startedAt)
proxy.Registry.CaptureRoutingRequest(routeEndpoint, startedAt)
proxy.Varz.CaptureRoutingResponse(routeEndpoint, endpointResponse, latency)
if err != nil {
proxy.Varz.CaptureBadGateway(request)
handler.HandleBadGateway(err)
return
}
accessLog.FirstByteAt = time.Now()
accessLog.Response = endpointResponse
if proxy.Config.TraceKey != "" && request.Header.Get(VcapTraceHeader) == proxy.Config.TraceKey {
handler.SetTraceHeaders(proxy.Config.Ip, routeEndpoint.CanonicalAddr())
}
bytesSent := handler.WriteResponse(endpointResponse)
accessLog.FinishedAt = time.Now()
accessLog.BodyBytesSent = bytesSent
}