Skip to content
This repository has been archived by the owner on Jan 31, 2018. It is now read-only.

Commit

Permalink
Merge pull request #55 from brianstarke/master
Browse files Browse the repository at this point in the history
Allow headers to be passed through in config
  • Loading branch information
David Ellis committed Aug 26, 2014
2 parents f939d20 + 66efdd9 commit 5b920c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/transports/client/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function HttpTransport(server, port, config) {
// and set the necessary elements
config = config || {};
this.path = config.path || '/';
this.headers = config.headers || {};
this.server = server;
this.port = port;

Expand All @@ -29,6 +30,7 @@ HttpTransport.prototype.request = function request(body, callback) {
hostname: this.server,
port: this.port,
path: this.path,
headers: this.headers,
method: 'POST'
}, function(res) {
// This one liner creates an anonymous queue assigned to `r`
Expand Down
14 changes: 12 additions & 2 deletions test/client-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ var HttpTransport = jsonrpc.transports.client.http;
var http = require('http');

exports.loopback = function(test) {
test.expect(1);
test.expect(3);
var server = http.createServer(function(req, res) {
test.equal('authToken', req.headers.authorization, 'authorization header received');
test.equal('thing', req.headers.other, 'other header received');

var buffer = '';
req.setEncoding('utf8');
req.on('data', function(data) {
Expand All @@ -16,7 +19,14 @@ exports.loopback = function(test) {
});
});
server.listen(12345, 'localhost', function() {
var httpTransport = new HttpTransport('localhost', 12345);
var options = {
headers: {
authorization: 'authToken',
other: 'thing'
}
};

var httpTransport = new HttpTransport('localhost', 12345, options);
httpTransport.request('foo', function(result) {
test.equal('foo', result, 'loopback works correctly');
server.close();
Expand Down

0 comments on commit 5b920c9

Please sign in to comment.