Add TO Golang server name header
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/46d1f4bf Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/46d1f4bf Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/46d1f4bf Branch: refs/heads/master Commit: 46d1f4bfe7c3b752a1d508f3029432139859530d Parents: 96edf7d Author: Robert Butts <robert.o.bu...@gmail.com> Authored: Fri Jul 21 18:59:16 2017 -0600 Committer: Dewayne Richardson <dewr...@apache.org> Committed: Thu Aug 10 09:46:03 2017 -0600 ---------------------------------------------------------------------- traffic_ops/traffic_ops_golang/routes.go | 2 +- traffic_ops/traffic_ops_golang/traffic_ops_golang.go | 4 +++- traffic_ops/traffic_ops_golang/wrappers.go | 10 ++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/46d1f4bf/traffic_ops/traffic_ops_golang/routes.go ---------------------------------------------------------------------- diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go index d7061b4..06f7bae 100644 --- a/traffic_ops/traffic_ops_golang/routes.go +++ b/traffic_ops/traffic_ops_golang/routes.go @@ -57,7 +57,7 @@ func GetRoutes(d ServerData) (map[string]RegexHandlerFunc, http.Handler, error) } return map[string]RegexHandlerFunc{ - "api/1.2/cdns/{cdn}/configs/monitoring.json": wrapAuth(monitoringHandler(d.DB), d.NoAuth, d.TOSecret, privLevelStmt, MonitoringPrivLevel), + "api/1.2/cdns/{cdn}/configs/monitoring.json": wrapHeaders(wrapAuth(monitoringHandler(d.DB), d.NoAuth, d.TOSecret, privLevelStmt, MonitoringPrivLevel)), }, getRootHandler(d), nil } http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/46d1f4bf/traffic_ops/traffic_ops_golang/traffic_ops_golang.go ---------------------------------------------------------------------- diff --git a/traffic_ops/traffic_ops_golang/traffic_ops_golang.go b/traffic_ops/traffic_ops_golang/traffic_ops_golang.go index 2689e7c..8f70098 100644 --- a/traffic_ops/traffic_ops_golang/traffic_ops_golang.go +++ b/traffic_ops/traffic_ops_golang/traffic_ops_golang.go @@ -30,7 +30,9 @@ import ( _ "github.com/lib/pq" ) -const DefaultConfigPath = "/etc/goto/config.json" +const Version = "0.1" + +const DefaultConfigPath = "/opt/traffic_ops/traffic_ops_golang.config" func main() { configFileName := flag.String("cfg", "", "The config file path") http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/46d1f4bf/traffic_ops/traffic_ops_golang/wrappers.go ---------------------------------------------------------------------- diff --git a/traffic_ops/traffic_ops_golang/wrappers.go b/traffic_ops/traffic_ops_golang/wrappers.go index c6eb8cf..64afeff 100644 --- a/traffic_ops/traffic_ops_golang/wrappers.go +++ b/traffic_ops/traffic_ops_golang/wrappers.go @@ -28,6 +28,16 @@ import ( "time" ) +const ServerName = "traffic_ops_golang" + "/" + Version + +func wrapHeaders(h RegexHandlerFunc) RegexHandlerFunc { + return func(w http.ResponseWriter, r *http.Request, p ParamMap) { + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("X-Server-Name", ServerName) + h(w, r, p) + } +} + func wrapAuth(h RegexHandlerFunc, noAuth bool, secret string, privLevelStmt *sql.Stmt, privLevelRequired int) RegexHandlerFunc { if noAuth { return h