Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Content-Length header in Traffic Router #4074

Merged
merged 18 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- [#7158](https://github.com/apache/trafficcontrol/issues/7158) *Traffic Vault* Fix the `reencrypt` utility to uniquely reencrypt each version of the SSL Certificates.
- [#7137](https://github.com/apache/trafficcontrol/pull/7137) *Cache Config* parent.config simulate topology for non topo delivery services.
- Adds an extra T3C check for validity of an ssl cert (crash fix).
- Traffic Router now always includes a `Content-Length` header in the response.

## [7.0.0] - 2022-07-19
### Added
Expand Down
123 changes: 64 additions & 59 deletions docs/source/development/traffic_router/traffic_router_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Request Structure

GET /crs/stats HTTP/1.1
Host: trafficrouter.infra.ciab.test
User-Agent: curl/7.47.0
User-Agent: curl/7.52.1
Accept: */*

Response Structure
Expand All @@ -80,14 +80,14 @@ Response Structure

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 15 Jan 2019 21:02:09 GMT
Content-Length: 1214
Date: Mon, 04 Nov 2019 19:48:04 GMT

{ "app": {
"buildTimestamp": "2019-01-10",
"buildTimestamp": "2019-11-04",
"name": "traffic_router",
"deploy-dir": "/opt/traffic_router",
"git-revision": "437e9df81",
"git-revision": "eabc2b82e",
"version": "3.0.0"
},
"stats": {
Expand All @@ -109,26 +109,26 @@ Response Structure
"totalDnsCount": 0,
"totalHttpCount": 1,
"totalDsMissCount": 0,
"appStartTime": 1547584831677,
"appStartTime": 1572895915703,
"averageDnsTime": 0,
"averageHttpTime": 1547584863270,
"averageHttpTime": 1572895947202,
"updateTracker": {
"lastHttpsCertificatesCheck": 1547586068932,
"lastGeolocationDatabaseUpdaterUpdate": 1547584858917,
"lastCacheStateCheck": 1547586128932,
"lastCacheStateChange": 1547584867102,
"lastNetworkUpdaterUpdate": 1547584857484,
"lastHttpsCertificatesUpdate": 1547586071079,
"lastSteeringWatcherUpdate": 1547584923514,
"lastConfigCheck": 1547586127344,
"lastConfigChange": 1547584863406,
"lastNetworkUpdaterCheck": 1547584857465,
"lastGeolocationDatabaseUpdaterCheck": 1547584858906,
"lastFederationsWatcherUpdate": 1547584863433,
"lastHttpsCertificatesFetchSuccess": 1547586069070,
"lastSteeringWatcherCheck": 1547586124630,
"lastFederationsWatcherCheck": 1547586124584,
"lastHttpsCertificatesFetchAttempt": 1547586068932
"lastHttpsCertificatesCheck": 1572896852436,
"lastGeolocationDatabaseUpdaterUpdate": 1572895942543,
"lastCacheStateCheck": 1572896884465,
"lastCacheStateChange": 1572895951089,
"lastNetworkUpdaterUpdate": 1572895941407,
"lastHttpsCertificatesUpdate": 1572896854512,
"lastSteeringWatcherUpdate": 1572896007369,
"lastConfigCheck": 1572896881213,
"lastConfigChange": 1572895947297,
"lastNetworkUpdaterCheck": 1572895941392,
"lastGeolocationDatabaseUpdaterCheck": 1572895942533,
"lastFederationsWatcherUpdate": 1572895947336,
"lastHttpsCertificatesFetchSuccess": 1572896852506,
"lastSteeringWatcherCheck": 1572896848090,
"lastFederationsWatcherCheck": 1572896848067,
"lastHttpsCertificatesFetchAttempt": 1572896852436
}
}}

Expand All @@ -153,7 +153,7 @@ Request Structure

GET /crs/stats/ip/255.255.255.255 HTTP/1.1
Host: trafficrouter.infra.ciab.test
User-Agent: curl/7.47.0
User-Agent: curl/7.52.1
Accept: */*

Response Structure
Expand All @@ -164,8 +164,8 @@ Response Structure
HTTP/1.1 200 OK
Content-Disposition: inline;filename=f.txt
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 15 Jan 2019 21:06:09 GMT
Content-Length: 131
Date: Mon, 04 Nov 2019 19:48:04 GMT

{ "locationByGeo": {
"city": "Woodridge",
Expand Down Expand Up @@ -194,7 +194,7 @@ Request Structure

GET /crs/locations HTTP/1.1
Host: trafficrouter.infra.ciab.test
User-Agent: curl/7.47.0
User-Agent: curl/7.52.1
Accept: */*

Response Structure
Expand All @@ -206,8 +206,8 @@ Response Structure

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 15 Jan 2019 21:12:17 GMT
Content-Length: 35
Date: Mon, 04 Nov 2019 19:48:04 GMT

{ "locations": [
"CDN_in_a_Box_Edge"
Expand All @@ -226,7 +226,7 @@ Request Structure

GET /crs/locations/caches HTTP/1.1
Host: trafficrouter.infra.ciab.test
User-Agent: curl/7.47.0
User-Agent: curl/7.52.1
Accept: */*

Response Structure
Expand All @@ -236,17 +236,17 @@ Response Structure

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 15 Jan 2019 21:15:53 GMT
Content-Length: 278
Date: Mon, 04 Nov 2019 19:48:04 GMT

{ "locations": {
"CDN_in_a_Box_Edge": [
{
"cacheId": "edge",
"fqdn": "edge.infra.ciab.test",
"ipAddresses": [
"172.16.239.100",
"fc01:9400:1000:8:0:0:0:100"
"172.16.239.4",
"fc01:9400:1000:8:0:0:0:4"
],
"port": 0,
"adminStatus": null,
Expand Down Expand Up @@ -282,7 +282,7 @@ Request Structure

GET /crs/locations/CDN_in_a_Box_Edge/caches HTTP/1.1
Host: trafficrouter.infra.ciab.test
User-Agent: curl/7.47.0
User-Agent: curl/7.52.1
Accept: */*

Response Structure
Expand All @@ -292,16 +292,16 @@ Response Structure

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 15 Jan 2019 21:18:25 GMT
Content-Length: 253
Date: Mon, 04 Nov 2019 19:48:04 GMT

{ "caches": [
{
"cacheId": "edge",
"fqdn": "edge.infra.ciab.test",
"ipAddresses": [
"172.16.239.100",
"fc01:9400:1000:8:0:0:0:100"
"172.16.239.4",
"fc01:9400:1000:8:0:0:0:4"
],
"port": 0,
"adminStatus": null,
Expand Down Expand Up @@ -409,7 +409,7 @@ Request Structure

GET /crs/consistenthash/deliveryservice?deliveryServiceId=demo1&requestPath=/ HTTP/1.1
Host: trafficrouter.infra.ciab.test
User-Agent: curl/7.47.0
User-Agent: curl/7.52.1
Accept: */*

Response Structure
Expand All @@ -419,8 +419,8 @@ Response Structure

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 15 Jan 2019 21:40:51 GMT
Content-Length: 828
Date: Mon, 04 Nov 2019 19:48:04 GMT

{ "id": "demo1",
"coverageZoneOnly": false,
Expand All @@ -429,8 +429,8 @@ Response Structure
"geoRedirectUrlType": "INVALID_URL",
"routingName": "video",
"missLocation": {
"latitude": 42,
"longitude": -88,
"latitude": 42.0,
"longitude": -88.0,
"postalCode": null,
"city": null,
"countryCode": null,
Expand Down Expand Up @@ -458,6 +458,13 @@ Response Structure
"sslEnabled": true,
"acceptHttp": true,
"deepCache": "NEVER",
"consistentHashRegex": "",
"consistentHashQueryParams": [
"abc",
"zyx",
"xxx",
"pdq"
],
"dns": false,
"locationLimit": 0,
"maxDnsIps": 0,
Expand Down Expand Up @@ -552,7 +559,7 @@ Request Structure

GET /crs/consistenthash/patternbased/regex?regex=%2F.*%3F%28%2F.*%3F%2F%29.*%3F%28%5C.m3u8%29&requestPath=%2Ftext1234%2Fname%2Fasset.m3u8 HTTP/1.1
Host: localhost:3333
User-Agent: curl/7.54.0
User-Agent: curl/7.52.1
Accept: */*

Response Structure
Expand All @@ -562,13 +569,12 @@ Response Structure

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 15 Feb 2019 22:06:53 GMT
Content-Length: 137
Date: Mon, 04 Nov 2019 19:48:04 GMT

{
"resultingPathToConsistentHash":"/name/.m3u8",
"consistentHashRegex":"/.*?(/.*?/).*?(\\.m3u8)",
"requestPath":"/text1234/name/asset.m3u8"
{ "resultingPathToConsistentHash": "/name/.m3u8",
"consistentHashRegex": "/.*?(/.*?/).*?(\\.m3u8)",
"requestPath": "/text1234/name/asset.m3u8"
}

.. _tr-api-crs-consistenthash-patternbased-deliveryservice:
Expand All @@ -592,9 +598,9 @@ Request Structure
.. code-block:: http
:caption: Request Example

GET /crs/consistenthash/patternbased/deliveryservice?deliveryServiceId=asdf&requestPath=%2Fsometext1234%2Fstream_name%2Fasset_name.m3u8 HTTP/1.1
GET /crs/consistenthash/patternbased/deliveryservice?deliveryServiceId=demo1&requestPath=%2Fsometext1234%2Fstream_name%2Fasset_name.m3u8 HTTP/1.1
Host: localhost:3333
User-Agent: curl/7.54.0
User-Agent: curl/7.52.1
Accept: */*

Response Structure
Expand All @@ -604,13 +610,12 @@ Response Structure

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 15 Feb 2019 22:12:38 GMT
Content-Length: 163
Date: Mon, 04 Nov 2019 19:48:04 GMT

{
"resultingPathToConsistentHash":"/sometext1234/stream_name/asset_name.m3u8",
"deliveryServiceId":"asdf",
"requestPath":"/sometext1234/stream_name/asset_name.m3u8"
{ "resultingPathToConsistentHash": "/sometext1234/stream_name/asset_name.m3u8",
"deliveryServiceId": "demo1",
"requestPath": "/sometext1234/stream_name/asset_name.m3u8"
}

.. _tr-api-crs-consistenthash-cache-coveragezone-steering:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ public class LocationController {
@Autowired
private DataExporter dataExporter;

@RequestMapping(value = "/{locID}/caches", method = RequestMethod.GET)
@RequestMapping(value = "/{locID}/caches", method = {RequestMethod.GET, RequestMethod.HEAD})
public @ResponseBody
Map<String, List<CacheModel>> getCaches(@PathVariable("locID") final String locId) {
final Map<String, List<CacheModel>> map = new HashMap<String, List<CacheModel>>();
map.put("caches", dataExporter.getCaches(locId));
return map;
}

@RequestMapping(value = "", method = RequestMethod.GET)
@RequestMapping(value = "", method = {RequestMethod.GET, RequestMethod.HEAD})
public @ResponseBody
Map<String,List<String>> getLocations() {
final Map<String, List<String >> locations = new HashMap<String, List<String>>();
Map<String, List<String>> getLocations() {
final Map<String, List<String>> locations = new HashMap<String, List<String>>();
locations.put("locations", dataExporter.getLocations());
return locations;
}

@RequestMapping(value = "/caches", method = RequestMethod.GET)
@RequestMapping(value = "/caches", method = {RequestMethod.GET, RequestMethod.HEAD})
public @ResponseBody
Map<String,Map<String, List<CacheModel>>> getCaches() {
Map<String, Map<String, List<CacheModel>>> getCaches() {
final Map<String, Map<String, List<CacheModel>>> map = new HashMap<String, Map<String, List<CacheModel>>>();
final Map<String, List<CacheModel>> innerMap = new HashMap<String, List<CacheModel>>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.traffic_control.traffic_router.core.http;

import org.springframework.web.util.ContentCachingResponseWrapper;

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class BufferedResponse extends ContentCachingResponseWrapper {
protected int contentLength;
protected ServletResponse response;

public BufferedResponse(final HttpServletResponse response) {
super(response);
this.response = response;
}

@Override
public void setContentLength(final int len) {
contentLength = len;
super.setContentLength(len);
}

@Override
public void setContentLengthLong(final long len) {
contentLength = (int) len;
super.setContentLengthLong(len);
}

@Override
public void copyBodyToResponse() throws IOException {
if (this.getContentSize() == 0) {
response.setContentLength(contentLength);
} else {
// When the content size is greater than 0, copyBodyToResponse()
// will set Content-Length.
super.copyBodyToResponse();
}
}
}
Loading