Fixed panic on redirection
This commit is contained in:
Toby Chui
2025-11-24 20:04:10 +08:00
parent bbb45b31f6
commit d5b1cbb78f

View File

@@ -363,7 +363,20 @@ func (router *Router) logRequest(r *http.Request, succ bool, statusCode int, for
// in that case we will log it by default and will not enter this routine // in that case we will log it by default and will not enter this routine
return return
} }
if router.Option.StatisticCollector != nil && !endpoint.DisableStatisticCollection {
router.Option.Logger.LogHTTPRequest(r, forwardType, statusCode, originalHostname, upstreamHostname)
if router.Option.StatisticCollector == nil {
// Statistic collection not yet initialized
return
}
if endpoint != nil && !endpoint.DisableStatisticCollection {
// Endpoint level statistic collection disabled
return
}
// Proceed to record the request info
go func() { go func() {
requestInfo := statistic.RequestInfo{ requestInfo := statistic.RequestInfo{
IpAddr: netutils.GetRequesterIP(r), IpAddr: netutils.GetRequesterIP(r),
@@ -380,6 +393,4 @@ func (router *Router) logRequest(r *http.Request, succ bool, statusCode int, for
router.Option.StatisticCollector.RecordRequest(requestInfo) router.Option.StatisticCollector.RecordRequest(requestInfo)
}() }()
}
router.Option.Logger.LogHTTPRequest(r, forwardType, statusCode, originalHostname, upstreamHostname)
} }