This is an automated email from the ASF dual-hosted git repository.
mattjackson 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 cd75524 Set content-type json on TR auth requests (#5000)
cd75524 is described below
commit cd75524e6e310972194f396b668b8eab173a2d30
Author: Eric Friedrich <[email protected]>
AuthorDate: Wed Sep 16 16:59:42 2020 -0400
Set content-type json on TR auth requests (#5000)
Co-authored-by: efriedrich <[email protected]>
---
CHANGELOG.md | 1 +
.../traffic_control/traffic_router/core/util/Fetcher.java | 12 ++++++++++++
.../traffic_router/core/util/ProtectedFetcher.java | 2 +-
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8cb98c0..4f3453c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -68,6 +68,7 @@ The format is based on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/).
- Added Delivery Service Raw Remap `__RANGE_DIRECTIVE__` directive to allow
inserting the Range Directive after the Raw Remap text. This allows Raw Remaps
which manipulate the Range.
- Added an option for `coordinateRange` in the RGB configuration file, so that
in case a client doesn't have a postal code, we can still determine if it
should be allowed or not, based on whether or not the latitude/ longitude of
the client falls within the supplied ranges. [Related github
issue](https://github.com/apache/trafficcontrol/issues/4372)
- Fixed #3548 - Prevents DS regexes with non-consecutive order from generating
invalid CRconfig/snapshot.
+- Fixed #4680 - Change Content-Type to application/json for TR auth calls
### Changed
- Changed some Traffic Ops Go Client methods to use `DeliveryServiceNullable`
inputs and outputs.
diff --git
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/Fetcher.java
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/Fetcher.java
index 8c62cce..3d4b847 100644
---
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/Fetcher.java
+++
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/Fetcher.java
@@ -47,9 +47,12 @@ public class Fetcher {
protected static final String UTF8_STR = "UTF-8";
protected static final int DEFAULT_TIMEOUT = 10000;
private static final String GZIP_ENCODING_STRING = "gzip";
+ private static final String CONTENT_TYPE_STRING = "Content-Type";
+ protected static final String CONTENT_TYPE_JSON = "application/json";
protected int timeout = DEFAULT_TIMEOUT; // override if you want
something different
protected final Map<String, String> requestProps = new HashMap<String,
String>();
+
static {
try {
// TODO: make disabling self signed certificates
configurable
@@ -72,6 +75,11 @@ public class Fetcher {
}
protected HttpURLConnection getConnection(final String url, final
String data, final String requestMethod, final long lastFetchTime) throws
IOException {
+ return getConnection(url, data, requestMethod, lastFetchTime,
null);
+ }
+
+ @SuppressWarnings("PMD.CyclomaticComplexity")
+ protected HttpURLConnection getConnection(final String url, final
String data, final String requestMethod, final long lastFetchTime, final String
contentType) throws IOException {
HttpURLConnection http = null;
try {
String method = GET_STR;
@@ -112,6 +120,10 @@ public class Fetcher {
http.addRequestProperty(key,
requestProps.get(key));
}
+ if (contentType != null) {
+ http.addRequestProperty(CONTENT_TYPE_STRING,
contentType);
+ }
+
if (method.equals(POST_STR) && data != null) {
http.setDoOutput(true); // Triggers POST.
diff --git
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/ProtectedFetcher.java
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/ProtectedFetcher.java
index 0edb429..b389a2c 100644
---
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/ProtectedFetcher.java
+++
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/ProtectedFetcher.java
@@ -33,7 +33,7 @@ public class ProtectedFetcher extends Fetcher {
@Override
protected HttpURLConnection getConnection(final String url, final
String data, final String method, final long lastFetchedTime) throws
IOException {
if (!isCookieValid()) {
-
extractCookie(super.getConnection(getAuthorizationEndpoint(), getData(),
POST_STR, 0L));
+
extractCookie(super.getConnection(getAuthorizationEndpoint(), getData(),
POST_STR, 0L, CONTENT_TYPE_JSON));
}
return extractCookie(super.getConnection(url, data, method,
lastFetchedTime));