This is an automated email from the ASF dual-hosted git repository.
rawlin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 4d91772de8 Default routeID to 0, if it is not present in the request
context (#6881)
4d91772de8 is described below
commit 4d91772de82207ef35621b7f1372993d79d53f72
Author: Srijeet Chatterjee <[email protected]>
AuthorDate: Thu Jun 2 14:56:11 2022 -0600
Default routeID to 0, if it is not present in the request context (#6881)
* Default routeID to 0, if it is not present in the request context
* add changelog
* code review
* remove itoa call
---
CHANGELOG.md | 1 +
traffic_ops/traffic_ops_golang/routing/middleware/wrappers.go | 3 ++-
traffic_ops/traffic_ops_golang/routing/routing.go | 4 ++--
3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 67bdef8de6..18bade89c8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@ The format is based on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/).
- Change to t3c regex_revalidate so that STALE is no longer explicitly added
for default revalidate rule for ATS version backwards compatibility.
### Fixed
+- Fixed TO to default route ID to 0, if it is not present in the request
context.
- [#6291](https://github.com/apache/trafficcontrol/issues/6291) Prevent
Traffic Ops from modifying and/or deleting reserved statuses.
- Update traffic\_portal dependencies to mitigate `npm audit` issues.
- Fixed a cdn-in-a-box build issue when using `RHEL_VERSION=7`
diff --git a/traffic_ops/traffic_ops_golang/routing/middleware/wrappers.go
b/traffic_ops/traffic_ops_golang/routing/middleware/wrappers.go
index 57ed0bb520..ca790eb950 100644
--- a/traffic_ops/traffic_ops_golang/routing/middleware/wrappers.go
+++ b/traffic_ops/traffic_ops_golang/routing/middleware/wrappers.go
@@ -212,7 +212,8 @@ func WrapAccessLog(secret string, h http.Handler)
http.HandlerFunc {
imsType = IMSMISS
}
}
- log.EventfRaw(`%s - %s [%s] "%v %v?%v %s" %v %v %v "%v"
%v %s`, r.RemoteAddr, user, time.Now().Format(AccessLogTimeFormat), r.Method,
r.URL.Path, r.URL.RawQuery, r.Proto, iw.Code, iw.ByteCount,
int(time.Now().Sub(start)/time.Millisecond), r.UserAgent(),
r.Context().Value(RouteID), imsType)
+ routeID, _ := r.Context().Value(RouteID).(int)
+ log.EventfRaw(`%s - %s [%s] "%v %v?%v %s" %v %v %v "%v"
%d %s`, r.RemoteAddr, user, time.Now().Format(AccessLogTimeFormat), r.Method,
r.URL.Path, r.URL.RawQuery, r.Proto, iw.Code, iw.ByteCount,
int(time.Now().Sub(start)/time.Millisecond), r.UserAgent(), routeID, imsType)
}()
h.ServeHTTP(iw, r)
}
diff --git a/traffic_ops/traffic_ops_golang/routing/routing.go
b/traffic_ops/traffic_ops_golang/routing/routing.go
index c3ca1adcb4..b09760868c 100644
--- a/traffic_ops/traffic_ops_golang/routing/routing.go
+++ b/traffic_ops/traffic_ops_golang/routing/routing.go
@@ -298,7 +298,7 @@ func Handler(
}
routeCtx := context.WithValue(ctx, api.PathParamsKey, params)
- routeCtx = context.WithValue(routeCtx, middleware.RouteID,
strconv.Itoa(compiledRoute.ID))
+ routeCtx = context.WithValue(routeCtx, middleware.RouteID,
compiledRoute.ID)
r = r.WithContext(routeCtx)
compiledRoute.Handler(w, r)
return
@@ -350,7 +350,7 @@ func Handler(
}
routeCtx := context.WithValue(ctx,
api.DBContextKey, db)
routeCtx = context.WithValue(routeCtx,
api.PathParamsKey, routeParams)
- routeCtx = context.WithValue(routeCtx,
middleware.RouteID, strconv.Itoa(backendRoute.ID))
+ routeCtx = context.WithValue(routeCtx,
middleware.RouteID, backendRoute.ID)
r = r.WithContext(routeCtx)
userErr, sysErr, code :=
HandleBackendRoute(cfg, backendRoute, w, r)
if userErr != nil || sysErr != nil {