This is an automated email from the ASF dual-hosted git repository.
ocket8888 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 5c71ca6f92 Using go-rfc for location header (#7748)
5c71ca6f92 is described below
commit 5c71ca6f92eb81fe220ac0a3ec3859c18f3f0d09
Author: Rima Shah <[email protected]>
AuthorDate: Sat Aug 26 00:06:28 2023 -0600
Using go-rfc for location header (#7748)
---
traffic_ops/traffic_ops_golang/asn/asns.go | 3 ++-
traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go | 3 ++-
traffic_ops/traffic_ops_golang/cdn/cdns.go | 3 ++-
traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go | 5 +++--
traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go | 4 ++--
traffic_ops/traffic_ops_golang/division/divisions.go | 3 ++-
traffic_ops/traffic_ops_golang/invalidationjobs/invalidationjobs.go | 2 +-
traffic_ops/traffic_ops_golang/physlocation/phys_locations.go | 3 ++-
traffic_ops/traffic_ops_golang/servercapability/servercapability.go | 5 +++--
traffic_ops/traffic_ops_golang/servicecategory/servicecategories.go | 3 ++-
traffic_ops/traffic_ops_golang/types/types.go | 3 ++-
traffic_ops/traffic_ops_golang/user/user.go | 2 +-
12 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/traffic_ops/traffic_ops_golang/asn/asns.go
b/traffic_ops/traffic_ops_golang/asn/asns.go
index b313d1295b..3e1e694b1c 100644
--- a/traffic_ops/traffic_ops_golang/asn/asns.go
+++ b/traffic_ops/traffic_ops_golang/asn/asns.go
@@ -29,6 +29,7 @@ import (
"time"
"github.com/apache/trafficcontrol/lib/go-log"
+ "github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
"github.com/apache/trafficcontrol/lib/go-util"
@@ -310,7 +311,7 @@ func Create(w http.ResponseWriter, r *http.Request) {
}
alerts := tc.CreateAlerts(tc.SuccessLevel, "asn was created.")
- w.Header().Set("Location", fmt.Sprintf("/api/%d.%d/asns?id=%d",
inf.Version.Major, inf.Version.Minor, asn.ID))
+ w.Header().Set(rfc.Location, fmt.Sprintf("/api/%s/asns?id=%d",
inf.Version, asn.ID))
api.WriteAlertsObj(w, r, http.StatusCreated, alerts, asn)
return
}
diff --git a/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
b/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
index f1d62d45b1..38ab868732 100644
--- a/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
+++ b/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
@@ -30,6 +30,7 @@ import (
"time"
"github.com/apache/trafficcontrol/lib/go-log"
+ "github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
"github.com/apache/trafficcontrol/lib/go-util"
@@ -1185,7 +1186,7 @@ func CreateCacheGroup(w http.ResponseWriter, r
*http.Request) {
}
alerts := tc.CreateAlerts(tc.SuccessLevel, "cache group was created.")
- w.Header().Set("Location",
fmt.Sprintf("/api/%d.%d/cachegroups?name=%s", inf.Version.Major,
inf.Version.Minor, *cg.Name))
+ w.Header().Set(rfc.Location, fmt.Sprintf("/api/%s/cachegroups?name=%s",
inf.Version, *cg.Name))
api.WriteAlertsObj(w, r, http.StatusCreated, alerts, cg)
return
}
diff --git a/traffic_ops/traffic_ops_golang/cdn/cdns.go
b/traffic_ops/traffic_ops_golang/cdn/cdns.go
index 31bfd0644d..8211767b11 100644
--- a/traffic_ops/traffic_ops_golang/cdn/cdns.go
+++ b/traffic_ops/traffic_ops_golang/cdn/cdns.go
@@ -30,6 +30,7 @@ import (
"time"
"github.com/apache/trafficcontrol/lib/go-log"
+ "github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
"github.com/apache/trafficcontrol/lib/go-util"
@@ -159,7 +160,7 @@ func Create(w http.ResponseWriter, r *http.Request) {
}
alerts := tc.CreateAlerts(tc.SuccessLevel, "cdn was created.")
- w.Header().Set("Location", fmt.Sprintf("/api/%d.%d/cdns?name=%s",
inf.Version.Major, inf.Version.Minor, cdn.Name))
+ w.Header().Set(rfc.Location, fmt.Sprintf("/api/%s/cdns?name=%s",
inf.Version, cdn.Name))
api.WriteAlertsObj(w, r, http.StatusCreated, alerts, cdn)
return
}
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go
b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go
index c1c6943351..19e0dc7d56 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go
@@ -33,6 +33,7 @@ import (
"time"
"github.com/apache/trafficcontrol/lib/go-log"
+ "github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
"github.com/apache/trafficcontrol/lib/go-util"
@@ -221,7 +222,7 @@ func CreateV50(w http.ResponseWriter, r *http.Request) {
alerts := res.TLSVersionsAlerts()
alerts.AddNewAlert(tc.SuccessLevel, "Delivery Service creation was
successful")
- w.Header().Set("Location",
fmt.Sprintf("/api/%d.%d/deliveryservices?id=%d", inf.Version.Major,
inf.Version.Minor, *res.ID))
+ w.Header().Set(rfc.Location,
fmt.Sprintf("/api/%s/deliveryservices?id=%d", inf.Version, *res.ID))
api.WriteAlertsObj(w, r, http.StatusCreated, alerts, *res)
}
@@ -249,7 +250,7 @@ func CreateV40(w http.ResponseWriter, r *http.Request) {
alerts := res.TLSVersionsAlerts()
alerts.AddNewAlert(tc.SuccessLevel, "Delivery Service creation was
successful")
- w.Header().Set("Location",
fmt.Sprintf("/api/%d.%d/deliveryservices?id=%d", inf.Version.Major,
inf.Version.Minor, *res.ID))
+ w.Header().Set(rfc.Location,
fmt.Sprintf("/api/%s/deliveryservices?id=%d", inf.Version, *res.ID))
api.WriteAlertsObj(w, r, http.StatusCreated, alerts,
[]tc.DeliveryServiceV40{*res})
}
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go
b/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go
index cc0e80a6b3..4addef68e4 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go
@@ -465,7 +465,7 @@ func createV5(w http.ResponseWriter, r *http.Request, inf
*api.APIInfo) (result
return
}
- w.Header().Set("Location",
fmt.Sprintf("/api/%d.%d/deliveryservice_requests/%d", inf.Version.Major,
inf.Version.Minor, *dsr.ID))
+ w.Header().Set(rfc.Location,
fmt.Sprintf("/api/%s/deliveryservice_requests/%d", inf.Version, *dsr.ID))
w.WriteHeader(http.StatusCreated)
api.WriteRespAlertObj(w, r, tc.SuccessLevel, "Delivery Service request
created", dsr)
@@ -535,7 +535,7 @@ func createV4(w http.ResponseWriter, r *http.Request, inf
*api.APIInfo) (result
dsr = upgraded.Downgrade()
- w.Header().Set("Location",
fmt.Sprintf("/api/%d.%d/deliveryservice_requests/%d", inf.Version.Major,
inf.Version.Minor, *dsr.ID))
+ w.Header().Set(rfc.Location,
fmt.Sprintf("/api/%s/deliveryservice_requests/%d", inf.Version, *dsr.ID))
w.WriteHeader(http.StatusCreated)
if inf.Version.Minor >= 1 {
api.WriteRespAlertObj(w, r, tc.SuccessLevel, "Delivery Service
request created", dsr)
diff --git a/traffic_ops/traffic_ops_golang/division/divisions.go
b/traffic_ops/traffic_ops_golang/division/divisions.go
index 406773ad09..2749e5f54c 100644
--- a/traffic_ops/traffic_ops_golang/division/divisions.go
+++ b/traffic_ops/traffic_ops_golang/division/divisions.go
@@ -30,6 +30,7 @@ import (
"time"
"github.com/apache/trafficcontrol/lib/go-log"
+ "github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
"github.com/apache/trafficcontrol/lib/go-util"
@@ -245,7 +246,7 @@ func CreateDivision(w http.ResponseWriter, r *http.Request)
{
return
}
alerts := tc.CreateAlerts(tc.SuccessLevel, "division was created.")
- w.Header().Set("Location", fmt.Sprintf("/api/%d.%d/divisons?name=%s",
inf.Version.Major, inf.Version.Minor, div.Name))
+ w.Header().Set(rfc.Location, fmt.Sprintf("/api/%s/divisons?name=%s",
inf.Version, div.Name))
api.WriteAlertsObj(w, r, http.StatusCreated, alerts, div)
return
}
diff --git
a/traffic_ops/traffic_ops_golang/invalidationjobs/invalidationjobs.go
b/traffic_ops/traffic_ops_golang/invalidationjobs/invalidationjobs.go
index 41a0f5a5aa..41cc0b4265 100644
--- a/traffic_ops/traffic_ops_golang/invalidationjobs/invalidationjobs.go
+++ b/traffic_ops/traffic_ops_golang/invalidationjobs/invalidationjobs.go
@@ -832,7 +832,7 @@ func Create(w http.ResponseWriter, r *http.Request) {
return
}
- w.Header().Set(http.CanonicalHeaderKey("location"),
fmt.Sprintf("%s://%s/api/%d.%d/jobs?id=%d", inf.Config.URL.Scheme, r.Host,
inf.Version.Major, inf.Version.Minor, *result.ID))
+ w.Header().Set(http.CanonicalHeaderKey("location"),
fmt.Sprintf("%s://%s/api/%s/jobs?id=%d", inf.Config.URL.Scheme, r.Host,
inf.Version, *result.ID))
w.WriteHeader(http.StatusOK)
api.WriteAndLogErr(w, r, append(resp, '\n'))
diff --git a/traffic_ops/traffic_ops_golang/physlocation/phys_locations.go
b/traffic_ops/traffic_ops_golang/physlocation/phys_locations.go
index 08770fb52e..d872a50e8b 100644
--- a/traffic_ops/traffic_ops_golang/physlocation/phys_locations.go
+++ b/traffic_ops/traffic_ops_golang/physlocation/phys_locations.go
@@ -29,6 +29,7 @@ import (
"time"
"github.com/apache/trafficcontrol/lib/go-log"
+ "github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
"github.com/apache/trafficcontrol/lib/go-util"
@@ -370,7 +371,7 @@ func CreatePhysLocation(w http.ResponseWriter, r
*http.Request) {
return
}
alerts := tc.CreateAlerts(tc.SuccessLevel, "physLocation was created.")
- w.Header().Set("Location",
fmt.Sprintf("/api/%d.%d/phys_locations?name=%s", inf.Version.Major,
inf.Version.Minor, physLocation.Name))
+ w.Header().Set(rfc.Location,
fmt.Sprintf("/api/%s/phys_locations?name=%s", inf.Version, physLocation.Name))
api.WriteAlertsObj(w, r, http.StatusCreated, alerts, physLocation)
return
}
diff --git
a/traffic_ops/traffic_ops_golang/servercapability/servercapability.go
b/traffic_ops/traffic_ops_golang/servercapability/servercapability.go
index 834a11e0e9..bf0d7918cf 100644
--- a/traffic_ops/traffic_ops_golang/servercapability/servercapability.go
+++ b/traffic_ops/traffic_ops_golang/servercapability/servercapability.go
@@ -28,6 +28,7 @@ import (
"time"
"github.com/apache/trafficcontrol/lib/go-log"
+ "github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
"github.com/apache/trafficcontrol/lib/go-util"
@@ -281,7 +282,7 @@ func CreateServerCapability(w http.ResponseWriter, r
*http.Request) {
return
}
alerts := tc.CreateAlerts(tc.SuccessLevel, "server capability was
created.")
- w.Header().Set("Location",
fmt.Sprintf("/api/%d.%d/server_capabilities?name=%s", inf.Version.Major,
inf.Version.Minor, sc.Name))
+ w.Header().Set(rfc.Location,
fmt.Sprintf("/api/%s/server_capabilities?name=%s", inf.Version, sc.Name))
api.WriteAlertsObj(w, r, http.StatusCreated, alerts, sc)
return
}
@@ -453,7 +454,7 @@ func CreateServerCapabilityV5(w http.ResponseWriter, r
*http.Request) {
return
}
alerts := tc.CreateAlerts(tc.SuccessLevel, "server capability was
created.")
- w.Header().Set("Location",
fmt.Sprintf("/api/%d.%d/server_capabilities?name=%s", inf.Version.Major,
inf.Version.Minor, sc.Name))
+ w.Header().Set(rfc.Location,
fmt.Sprintf("/api/%s/server_capabilities?name=%s", inf.Version, sc.Name))
api.WriteAlertsObj(w, r, http.StatusCreated, alerts, sc)
return
}
diff --git
a/traffic_ops/traffic_ops_golang/servicecategory/servicecategories.go
b/traffic_ops/traffic_ops_golang/servicecategory/servicecategories.go
index 348efb728e..59f383a975 100644
--- a/traffic_ops/traffic_ops_golang/servicecategory/servicecategories.go
+++ b/traffic_ops/traffic_ops_golang/servicecategory/servicecategories.go
@@ -28,6 +28,7 @@ import (
"time"
"github.com/apache/trafficcontrol/lib/go-log"
+ "github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
"github.com/apache/trafficcontrol/lib/go-util"
@@ -332,7 +333,7 @@ func CreateServiceCategory(w http.ResponseWriter, r
*http.Request) {
return
}
alerts := tc.CreateAlerts(tc.SuccessLevel, "service category was
created.")
- w.Header().Set("Location",
fmt.Sprintf("/api/%d.%d/service_category?name=%s", inf.Version.Major,
inf.Version.Minor, sc.Name))
+ w.Header().Set(rfc.Location,
fmt.Sprintf("/api/%s/service_category?name=%s", inf.Version, sc.Name))
api.WriteAlertsObj(w, r, http.StatusCreated, alerts, sc)
return
}
diff --git a/traffic_ops/traffic_ops_golang/types/types.go
b/traffic_ops/traffic_ops_golang/types/types.go
index ed77f4b941..4d81073579 100644
--- a/traffic_ops/traffic_ops_golang/types/types.go
+++ b/traffic_ops/traffic_ops_golang/types/types.go
@@ -29,6 +29,7 @@ import (
"time"
"github.com/apache/trafficcontrol/lib/go-log"
+ "github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
"github.com/apache/trafficcontrol/lib/go-util"
@@ -323,7 +324,7 @@ func Create(w http.ResponseWriter, r *http.Request) {
return
}
alerts := tc.CreateAlerts(tc.SuccessLevel, "type was created.")
- w.Header().Set("Location", fmt.Sprintf("/api/%d.%d/type?name=%s",
inf.Version.Major, inf.Version.Minor, typ.Name))
+ w.Header().Set(rfc.Location, fmt.Sprintf("/api/%s/type?name=%s",
inf.Version, typ.Name))
api.WriteAlertsObj(w, r, http.StatusCreated, alerts, typ)
return
}
diff --git a/traffic_ops/traffic_ops_golang/user/user.go
b/traffic_ops/traffic_ops_golang/user/user.go
index 89b3fea9a2..38e9f7b19b 100644
--- a/traffic_ops/traffic_ops_golang/user/user.go
+++ b/traffic_ops/traffic_ops_golang/user/user.go
@@ -903,7 +903,7 @@ func Create(w http.ResponseWriter, r *http.Request) {
Response: userV4,
Alerts: tc.CreateAlerts(tc.SuccessLevel, "user was created."),
}
- w.Header().Set("Location", fmt.Sprintf("/api/%d.%d/users?id=%d",
inf.Version.Major, inf.Version.Minor, *userV4.ID))
+ w.Header().Set(rfc.Location, fmt.Sprintf("/api/%s/users?id=%d",
inf.Version, *userV4.ID))
api.WriteAlertsObj(w, r, http.StatusCreated, userResponse.Alerts,
userResponse.Response)
changeLogMsg = fmt.Sprintf("USER: %s, ID: %d, ACTION: Created User",
userV4.Username, *userV4.ID)
api.CreateChangeLogRawTx(api.ApiChange, changeLogMsg, inf.User, tx)