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 9623b4d  Use RFC lib and correct Content-Type on TM api (#4951)
9623b4d is described below

commit 9623b4deec437c7d7eaab1ee2d97e7cf9dde4b01
Author: Steve Hamrick <[email protected]>
AuthorDate: Wed Aug 26 15:10:49 2020 -0600

    Use RFC lib and correct Content-Type on TM api (#4951)
    
    * Use rfc lib and correct content-type
    
    * Code review fix
---
 lib/go-rfc/http.go                 |  1 +
 traffic_monitor/datareq/datareq.go | 41 +++++++++++++++++++-------------------
 2 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/lib/go-rfc/http.go b/lib/go-rfc/http.go
index e9ecd1a..156bbc0 100644
--- a/lib/go-rfc/http.go
+++ b/lib/go-rfc/http.go
@@ -48,6 +48,7 @@ const (
        ApplicationOctetStream    = "application/octet-stream" // RFC2046§4.5.2
        ContentTypeMultiPartMixed = "multipart/mixed"          // RFC1341§7.2
        ContentTypeTextPlain      = "text/plain"               // RFC2046§4.1
+       ContentTypeURIList        = "text/uri-list"            // RFC2483§5
        Gzip                      = "gzip"                     // RFC7230§4.2.3
 )
 
diff --git a/traffic_monitor/datareq/datareq.go 
b/traffic_monitor/datareq/datareq.go
index 19689d3..ea0cfca 100644
--- a/traffic_monitor/datareq/datareq.go
+++ b/traffic_monitor/datareq/datareq.go
@@ -30,6 +30,7 @@ import (
        "unicode"
 
        "github.com/apache/trafficcontrol/lib/go-log"
+       "github.com/apache/trafficcontrol/lib/go-rfc"
        "github.com/apache/trafficcontrol/traffic_monitor/config"
        "github.com/apache/trafficcontrol/traffic_monitor/health"
        "github.com/apache/trafficcontrol/traffic_monitor/peer"
@@ -72,62 +73,62 @@ func MakeDispatchMap(
        dispatchMap := map[string]http.HandlerFunc{
                "/publish/CrConfig": wrap(WrapAgeErr(errorCount, func() 
([]byte, time.Time, error) {
                        return srvTRConfig(opsConfig, toSession)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/publish/CrStates": wrap(WrapParams(func(params url.Values, 
path string) ([]byte, int) {
                        bytes, statusCode, err := srvTRState(params, 
localStates, combinedStates, peerStates)
                        return WrapErrStatusCode(errorCount, path, bytes, 
statusCode, err)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/publish/CacheStats": wrap(WrapParams(func(params url.Values, 
path string) ([]byte, int) {
                        return srvCacheStats(params, errorCount, path, toData, 
statResultHistory, statInfoHistory, monitorConfig, combinedStates, 
statMaxKbpses)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/publish/DsStats": wrap(WrapParams(func(params url.Values, 
path string) ([]byte, int) {
                        return srvDSStats(params, errorCount, path, toData, 
dsStats)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/publish/EventLog": wrap(WrapErr(errorCount, func() ([]byte, 
error) {
                        return srvEventLog(events)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/publish/PeerStates": wrap(WrapParams(func(params url.Values, 
path string) ([]byte, int) {
                        return srvPeerStates(params, errorCount, path, toData, 
peerStates)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/publish/Stats": wrap(WrapErr(errorCount, func() ([]byte, 
error) {
                        return srvStats(staticAppData, healthPollInterval, 
lastHealthDurations, fetchCount, healthIteration, errorCount, peerStates)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/publish/ConfigDoc": wrap(WrapErr(errorCount, func() ([]byte, 
error) {
                        return srvConfigDoc(opsConfig)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/publish/StatSummary": wrap(WrapParams(func(params url.Values, 
path string) ([]byte, int) {
                        return srvStatSummary(params, errorCount, path, toData, 
statResultHistory)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/api/cache-count": wrap(WrapBytes(func() []byte {
                        return srvAPICacheCount(localStates)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/api/cache-available-count": wrap(WrapBytes(func() []byte {
                        return srvAPICacheAvailableCount(localStates)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/api/cache-down-count": wrap(WrapBytes(func() []byte {
                        return srvAPICacheDownCount(localStates, monitorConfig)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/api/version": wrap(WrapBytes(func() []byte {
                        return srvAPIVersion(staticAppData)
-               }, ContentTypeJSON)),
+               }, rfc.ContentTypeTextPlain)),
                "/api/traffic-ops-uri": wrap(WrapBytes(func() []byte {
                        return srvAPITrafficOpsURI(opsConfig)
-               }, ContentTypeJSON)),
+               }, rfc.ContentTypeURIList)),
                "/api/cache-statuses": wrap(WrapErr(errorCount, func() ([]byte, 
error) {
                        return srvAPICacheStates(toData, statInfoHistory, 
statResultHistory, healthHistory, lastHealthDurations, localStates, lastStats, 
localCacheStatus, statMaxKbpses, monitorConfig)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/api/bandwidth-kbps": wrap(WrapBytes(func() []byte {
                        return srvAPIBandwidthKbps(toData, lastStats)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/api/bandwidth-capacity-kbps": wrap(WrapBytes(func() []byte {
                        return srvAPIBandwidthCapacityKbps(statMaxKbpses)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/api/monitor-config": wrap(WrapErr(errorCount, func() ([]byte, 
error) {
                        return srvMonitorConfig(monitorConfig)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
                "/api/crconfig-history": wrap(WrapErr(errorCount, func() 
([]byte, error) {
                        return srvAPICRConfigHist(toSession)
-               }, ContentTypeJSON)),
+               }, rfc.ApplicationJSON)),
        }
        return addTrailingSlashEndpoints(dispatchMap)
 }
@@ -286,8 +287,6 @@ func wrapUnpolledCheck(unpolledCaches 
threadsafe.UnpolledCaches, errorCount thre
        }
 }
 
-const ContentTypeJSON = "application/json"
-
 func stripAllWhitespace(s string) string {
        return strings.Map(func(r rune) rune {
                if unicode.IsSpace(r) {

Reply via email to