Skip to content
This repository

hack to pass host #17

Open
wants to merge 1 commit into from

2 participants

seebees Tim
seebees

I would not blame you if you don't want to take this. But the test is sound. I can submit just the test is you like...

Making insert_headers able to modify Host seemed to be the "best" way... sigh, let me know...

remery hack to pass host
Evil Evil hack to re-write the host header
68f02e7
Tim

So i take it i cant overwrite the host in the headers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 09, 2011
remery hack to pass host
Evil Evil hack to re-write the host header
68f02e7
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 53 additions and 0 deletions. Show diff stats Hide diff stats

  1. +3 0  index.js
  2. +50 0 test/host.js
3  index.js
@@ -83,6 +83,9 @@ function makeBounce (bs, client, req) {
83 83 opts.headers['x-forwarded-proto'] =
84 84 client.encrypted ? 'https' : 'http';
85 85 }
  86 + if (opts.host && bs.chunks[4].toString() === 'Host:') {
  87 + bs.chunks[5] = new Buffer(' ' + opts.host + '\r\n');
  88 + }
86 89
87 90 insertHeaders(bs.chunks, opts.headers);
88 91
50 test/host.js
... ... @@ -0,0 +1,50 @@
  1 +var test = require('tap').test;
  2 +var http = require('http');
  3 +var net = require('net');
  4 +var bouncy = require('../');
  5 +
  6 +test('bounce host sugar', function (t) {
  7 + var p0 = Math.floor(Math.random() * (Math.pow(2,16) - 1e4) + 1e4);
  8 + var s0 = http.createServer(function (req, res) {
  9 + console.log(req);
  10 + t.equal(req.headers['host'], '127.0.0.1');
  11 + res.setHeader('content-type', 'text/plain');
  12 + res.write('beep boop');
  13 + res.end();
  14 + });
  15 + s0.listen(p0, connect);
  16 +
  17 + var p1 = Math.floor(Math.random() * (Math.pow(2,16) - 1e4) + 1e4);
  18 + var s1 = bouncy(function (req, bounce) {
  19 + bounce('127.0.0.1', p0);
  20 + });
  21 + s1.listen(p1, connect);
  22 +
  23 + var connected = 0;
  24 + function connect () {
  25 + if (++connected !== 2) return;
  26 + var opts = {
  27 + method : 'GET',
  28 + host : 'localhost',
  29 + port : p1,
  30 + path : '/beep'
  31 + };
  32 + var req = http.request(opts, function (res) {
  33 + t.equal(res.statusCode, 200)
  34 + t.equal(res.headers['content-type'], 'text/plain');
  35 +
  36 + var data = '';
  37 + res.on('data', function (buf) {
  38 + data += buf.toString();
  39 + });
  40 +
  41 + res.on('end', function () {
  42 + t.equal(data, 'beep boop');
  43 + s0.close();
  44 + s1.close();
  45 + t.end();
  46 + });
  47 + });
  48 + req.end();
  49 + }
  50 +});

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.