Skip to content

Commit

Permalink
Handle headers as lowercase
Browse files Browse the repository at this point in the history
Fixes #205
  • Loading branch information
Matt Loring committed Feb 1, 2016
1 parent 261b3fd commit 3dba572
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

module.exports = {
/** @const {string} header that carries trace context across Google infrastructure. */
TRACE_CONTEXT_HEADER_NAME: 'X-Cloud-Trace-Context',
TRACE_CONTEXT_HEADER_NAME: 'x-cloud-trace-context',

/** @const {string} header that is used to identify outgoing http made by the agent. */
TRACE_AGENT_REQUEST_HEADER: 'X-Cloud-Trace-Agent-Request'
TRACE_AGENT_REQUEST_HEADER: 'x-cloud-trace-agent-request'
};
43 changes: 41 additions & 2 deletions test/standalone/test-trace-header-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ var express = require('../hooks/fixtures/express4');
var constants = require('../../lib/constants.js');

describe('test-trace-header-context', function() {
beforeEach(function() {
require('../..').start();
});

afterEach(function() {
require('../..').stop();
});

it('should work with string url', function(done) {
var app = express();
var server;
Expand All @@ -30,7 +38,7 @@ describe('test-trace-header-context', function() {
res.send(common.serverRes);
});
app.get('/self', function(req, res) {
assert(req.headers[constants.TRACE_CONTEXT_HEADER_NAME.toLowerCase()]);
assert(req.headers[constants.TRACE_CONTEXT_HEADER_NAME]);
res.send(common.serverRes);
var traces = common.getTraces();
assert.equal(traces.length, 2);
Expand All @@ -56,7 +64,7 @@ describe('test-trace-header-context', function() {
res.send(common.serverRes);
});
app.get('/self', function(req, res) {
assert(req.headers[constants.TRACE_CONTEXT_HEADER_NAME.toLowerCase()]);
assert(req.headers[constants.TRACE_CONTEXT_HEADER_NAME]);
res.send(common.serverRes);
var traces = common.getTraces();
assert.equal(traces.length, 2);
Expand All @@ -73,4 +81,35 @@ describe('test-trace-header-context', function() {
http.get({ port: common.serverPort });
});
});

it('should parse incoming header', function(done) {
var app = express();
var server;
var context = '123456/2';
app.get('/', function (req, res) {
http.get({ port: common.serverPort, path: '/self'});
res.send(common.serverRes);
});
app.get('/self', function(req, res) {
assert.equal(
req.headers[constants.TRACE_CONTEXT_HEADER_NAME].slice(0, 6),
context.slice(0, 6));
res.send(common.serverRes);
var traces = common.getTraces();
assert.equal(traces.length, 2);
assert.equal(traces[0].spans.length, 2);
assert.equal(traces[1].spans.length, 1);
assert.equal(traces[0].spans[0].name, '/');
assert.equal(traces[0].spans[1].name, 'http://localhost:9042/self');
assert.equal(traces[1].spans[0].name, '/self');
common.cleanTraces();
server.close();
done();
});
server = app.listen(common.serverPort, function() {
var headers = {};
headers[constants.TRACE_CONTEXT_HEADER_NAME] = context;
http.get({ port: common.serverPort, headers: headers });
});
});
});
4 changes: 2 additions & 2 deletions test/test-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var constants = require('../lib/constants.js');

describe('constants', function() {
it('has correct values', function() {
assert.equal(constants.TRACE_CONTEXT_HEADER_NAME, 'X-Cloud-Trace-Context');
assert.equal(constants.TRACE_AGENT_REQUEST_HEADER, 'X-Cloud-Trace-Agent-Request');
assert.equal(constants.TRACE_CONTEXT_HEADER_NAME, 'x-cloud-trace-context');
assert.equal(constants.TRACE_AGENT_REQUEST_HEADER, 'x-cloud-trace-agent-request');
});
});

0 comments on commit 3dba572

Please sign in to comment.