Skip to content

Commit

Permalink
v0.1.5: Added a rule for Akamai and a note about forcing headers
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed May 12, 2018
1 parent 53eb84d commit 82f371e
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 18 deletions.
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cdn-detector.js

v0.1.4
v0.1.5

[http://nicj.net](http://nicj.net)

Expand Down Expand Up @@ -155,6 +155,32 @@ Via `gulp`, these are built as `data/*.js` and are included in the `dist/*.js` f

In NodeJS, these files are used as-is.

## Forcing Headers

Some CDNs may require a HTTP Request Header to be present before they expose a HTTP
Response Header that can be used for fingerprinting.

Known examples:

* [Akamai](https://community.akamai.com/community/web-performance/blog/2015/03/31/using-akamai-pragma-headers-to-investigate-or-troubleshoot-akamai-content-delivery):
`Pragma: akamai-x-get-request-id` will return a `X-Akamai-Request-ID`

If you're using [`request`](https://github.com/request/request) to fetch the
headers, you would add the HTTP Request Header to the `request()` options:

```js
request({
url: url,
gzip: true,
time: true,
headers: {
'pragma': 'akamai-x-get-request-id'
}
}, function(err, response, body) {
...
});
```

## Tests

Tests are provided in the `test/` directory, and can be run via `mocha`:
Expand All @@ -168,7 +194,8 @@ Or via ``gulp``:
## Version History

* v0.1.0 - 2016-08-17: Initial version
* v0.1.1 - 2016-08-17: Changed what inedx points to
* v0.1.2 - 2016-08-17: Fixed module.exports
* v0.1.1 - 2016-08-17: Changed what `index.js` points to
* v0.1.2 - 2016-08-17: Fixed `module.exports`
* v0.1.3 - 2016-10-31: jQuery CDN added
* v0.1.4 - 2017-07-02: CDN list updated
* v0.1.5 - 2018-05-12: Added a rule for Akamai and a note about forcing headers
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cdn-detector",
"version": "0.1.4",
"version": "0.1.5",
"homepage": "https://github.com/nicjansma/cdn-detector.js",
"authors": [
"Nic Jansma <nic@nicj.net>"
Expand Down
5 changes: 5 additions & 0 deletions data/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ var CdnDetectorHeaders = [
"rev-cache",
"Rev Software"
],
[
"x-akamai-request-id",
"",
"Akamai"
],
[
"x-amz-cf-id",
"",
Expand Down
1 change: 1 addition & 0 deletions data/headers.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
["via", "bitgravity", "BitGravity"],
["via", "cloudfront", "Amazon CloudFront"],
["via", "rev-cache", "Rev Software"],
["x-akamai-request-id", "", "Akamai"],
["x-amz-cf-id", "", "Amazon CloudFront"],
["x-ar-debug", "", "Aryaka"],
["x-cache", "cache.51cdn.com", "ChinaNetCenter"],
Expand Down
32 changes: 20 additions & 12 deletions dist/cdn-detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ var CdnDetectorHeaders = [
"rev-cache",
"Rev Software"
],
[
"x-akamai-request-id",
"",
"Akamai"
],
[
"x-amz-cf-id",
"",
Expand Down Expand Up @@ -403,6 +408,7 @@ var CdnDetectorMultiHeaders = [
//
// https://github.com/nicjansma/cdn-detector.js
//
/* eslint-env commonjs, browser, amd */
(function(window) {
"use strict";

Expand Down Expand Up @@ -554,19 +560,21 @@ var CdnDetectorMultiHeaders = [

// convert all incoming headers to lower case first
var lowerHeaders = {};
for (var header in headers) {
if (headers.hasOwnProperty(header)) {
lowerHeaders[header.toLowerCase()] = headers[header];
for (var headerName in headers) {
if (headers.hasOwnProperty(headerName)) {
lowerHeaders[headerName.toLowerCase()] = headers[headerName];
}
}

var i, data, cdn, match, matches;

// find any matching headers in our data
for (var i = 0; i < headersData.length; i++) {
var data = headersData[i];
for (i = 0; i < headersData.length; i++) {
data = headersData[i];

var header = data[0];
var match = data[1];
var cdn = data[2];
match = data[1];
cdn = data[2];

if (typeof lowerHeaders[header] === "string") {
// if there is no match string, we're good
Expand All @@ -580,18 +588,18 @@ var CdnDetectorMultiHeaders = [
}

// find any multi headers (multiple headers need to match)
for (var i = 0; i < multiHeadersData.length; i++) {
var data = multiHeadersData[i];
for (i = 0; i < multiHeadersData.length; i++) {
data = multiHeadersData[i];

var cdn = data[0];
var matches = data[1];
cdn = data[0];
matches = data[1];

var matchesAll = true;
var matchEvidence = [];

// loop through, looking to see if this request matches
// all headers in the set
for (var match in matches) {
for (match in matches) {
if (matches.hasOwnProperty(match)) {
var matchValue = matches[match];

Expand Down
2 changes: 1 addition & 1 deletion dist/cdn-detector.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cdn-detector",
"version": "0.1.4",
"version": "0.1.5",
"description": "CDN detection",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 12 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@

expect(result).to.equal(null);
});

it("should detect Akamai with x-akamai-request-id", function() {
var result = cd.detectFromHeaders({
"X-Akamai-Request-ID": "2256a92",
});

expect(result).to.not.equal(null);

expect(result.cdn).to.equal("Akamai");

expect(result.evidence).to.contain("x-akamai-request-id: *");
});
});
});
}(typeof window !== "undefined" ? window : undefined));

0 comments on commit 82f371e

Please sign in to comment.