Skip to content

Commit

Permalink
Tread HTTP headers case-insensitively (#3694)
Browse files Browse the repository at this point in the history
  • Loading branch information
l1bbcsg committed Jul 20, 2021
1 parent 7ddda30 commit 37d815b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/dash/DashMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ function DashMetrics(config) {
* @instance
*/
function getLatestMPDRequestHeaderValueByID(id) {
if (!id) {
return null;
}

let headers = {};
let httpRequestList,
httpRequest,
Expand All @@ -427,7 +431,8 @@ function DashMetrics(config) {
}
}

return headers[id] === undefined ? null : headers[id];
const value = headers[id.toLowerCase()];
return value === undefined ? null : value;
}

/**
Expand All @@ -439,12 +444,18 @@ function DashMetrics(config) {
* @instance
*/
function getLatestFragmentRequestHeaderValueByID(mediaType, id) {
if (!id) {
return null;
}

let headers = {};
let httpRequest = getCurrentHttpRequest(mediaType, true);
let httpRequest = getCurrentHttpRequest(mediaType);
if (httpRequest) {
headers = Utils.parseHttpHeaders(httpRequest._responseHeaders);
}
return headers[id] === undefined ? null : headers[id];

const value = headers[id.toLowerCase()];
return value === undefined ? null : value;
}

/**
Expand Down
24 changes: 24 additions & 0 deletions test/unit/dash.DashMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,19 @@ describe('DashMetrics', function () {
});

describe('getLatestMPDRequestHeaderValueByID', () => {
it('should treat headers case-insensitively', () => {
const metrics = { HttpList: [{type: 'MPD', _responseHeaders: 'date: mock'}]};
metricsModelMock.setMetrics(metrics);

const lowerCaseValue = dashMetrics.getLatestMPDRequestHeaderValueByID('date');
const upperCaseValue = dashMetrics.getLatestMPDRequestHeaderValueByID('Date');

expect(lowerCaseValue).to.equal('mock');
expect(upperCaseValue).to.equal('mock');
});

it('should return null when getLatestMPDRequestHeaderValueByID is called and id is undefined', () => {
metricsModelMock.setMetrics({});
const lastMpdRequestHeader = dashMetrics.getLatestMPDRequestHeaderValueByID();

expect(lastMpdRequestHeader).to.be.null; // jshint ignore:line
Expand All @@ -80,7 +92,19 @@ describe('DashMetrics', function () {
});

describe('getLatestFragmentRequestHeaderValueByID', () => {
it('should treat headers case-insensitively', () => {
const metrics = { HttpList: [{responsecode: 200, _responseHeaders: 'date: mock'}]};
metricsModelMock.setMetrics(metrics);

const lowerCaseValue = dashMetrics.getLatestFragmentRequestHeaderValueByID('stream', 'date');
const upperCaseValue = dashMetrics.getLatestFragmentRequestHeaderValueByID('stream', 'Date');

expect(lowerCaseValue).to.equal('mock');
expect(upperCaseValue).to.equal('mock');
});

it('should return null when getLatestFragmentRequestHeaderValueByID is called and metrics, type and id are undefined', () => {
metricsModelMock.setMetrics({});
const lastFragmentRequestHeader = dashMetrics.getLatestFragmentRequestHeaderValueByID();

expect(lastFragmentRequestHeader).to.be.null; // jshint ignore:line
Expand Down

0 comments on commit 37d815b

Please sign in to comment.