Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: http-party/node-http-proxy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.4.3
Choose a base ref
...
head repository: http-party/node-http-proxy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.5.0
Choose a head ref
  • 13 commits
  • 5 files changed
  • 5 contributors

Commits on Sep 16, 2014

  1. handle 'upgrade' in comma-separated connection header

    Firefox sends `keep-alive, upgrade`, not just `upgrade`,
    which the proxy incorrectly turned into `close`
    minrk committed Sep 16, 2014
    Copy the full SHA
    51eeebe View commit details
  2. use regex to check for upgrade header

    in websocket connections
    minrk committed Sep 16, 2014
    Copy the full SHA
    65a21bc View commit details
  3. Copy the full SHA
    ec683b9 View commit details
  4. Merge pull request #691 from minrk/firefox-ws-connection-close

    handle 'upgrade' in comma-separated connection header
    jcrugzz committed Sep 16, 2014
    Copy the full SHA
    42c35ae View commit details
  5. Fix typo in README.md

    "Is it then possible" -> "It is then possible"
    shebson committed Sep 16, 2014
    Copy the full SHA
    45cf95a View commit details
  6. Merge pull request #702 from shebson/fix-readme-typo

    Fix typo in README.md
    jcrugzz committed Sep 16, 2014
    Copy the full SHA
    90d40d6 View commit details

Commits on Sep 17, 2014

  1. Copy the full SHA
    c0a796b View commit details

Commits on Sep 26, 2014

  1. [minor] extra space

    jcrugzz committed Sep 26, 2014
    Copy the full SHA
    e7d50b1 View commit details
  2. Fixed misleading documentation

    options.xfwd definitely works fine without using the .listen method, and, AFAICT, .toProxy should as well.  Only .ssl and .ws are referenced in .listen.
    Jimbly committed Sep 26, 2014
    Copy the full SHA
    a4ca578 View commit details
  3. Merge pull request #705 from Jimbly/patch-1

    Fixed misleading documentation
    jcrugzz committed Sep 26, 2014
    Copy the full SHA
    2aa3b84 View commit details

Commits on Sep 30, 2014

  1. emitting proxySocket on proxyServer

    - emitted once proxySocket was created and socket was piped into it
    - needed to support sniffing messages coming from proxy target
    thlorenz committed Sep 30, 2014
    Copy the full SHA
    000eb53 View commit details
  2. Merge pull request #706 from thlorenz/expose-proxy-socket

    exposing proxySocket on socket to support sniffing messages coming from proxy target
    jcrugzz committed Sep 30, 2014
    Copy the full SHA
    9210b56 View commit details
  3. [dist] Version bump. 1.5.0

    jcrugzz committed Sep 30, 2014
    Copy the full SHA
    232258b View commit details
Showing with 58 additions and 5 deletions.
  1. +11 −3 README.md
  2. +2 −1 lib/http-proxy/common.js
  3. +1 −0 lib/http-proxy/passes/ws-incoming.js
  4. +1 −1 package.json
  5. +43 −0 test/lib-http-proxy-common-test.js
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ An object will be returned with four values:
* listen `port` (a function that wraps the object in a webserver, for your convenience)
* close `[callback]` (a function that closes the inner webserver and stops listening on given port)

Is it then possible to proxy requests by calling these functions
It is then possible to proxy requests by calling these functions

```javascript
http.createServer(function(req, res) {
@@ -190,6 +190,7 @@ http.createServer(function (req, res) {

* `error`: The error event is emitted if the request to the target fail.
* `proxyRes`: This event is emitted if the request to the target got a response.
* `proxySocket`: This event is emitted once the proxy websocket was created and piped into the target websocket.

```js
var httpProxy = require('http-proxy');
@@ -220,6 +221,13 @@ proxy.on('proxyRes', function (proxyRes, req, res) {
console.log('RAW Response from the target', JSON.stringify(proxyRes.headers, true, 2));
});

//
// Listen for the `proxySocket` event on `proxy`.
//
proxy.on('proxySocket', function (proxySocket) {
// listen for messages coming FROM the target here
proxySocket.on('data', hybiParseAndLogMessage);
});
```

#### Using HTTPS
@@ -315,13 +323,13 @@ proxyServer.listen(8015);
* **forward**: url string to be parsed with the url module
* **agent**: object to be passed to http(s).request (see Node's [https agent](http://nodejs.org/api/https.html#https_class_https_agent) and [http agent](http://nodejs.org/api/http.html#http_class_http_agent) objects)
* **secure**: true/false, if you want to verify the SSL Certs
* **xfwd**: true/false, adds x-forward headers
* **toProxy**: passes the absolute URL as the `path` (useful for proxying to proxies)

If you are using the `proxyServer.listen` method, the following options are also applicable:

* **ssl**: object to be passed to https.createServer()
* **ws**: true/false, if you want to proxy websockets
* **xfwd**: true/false, adds x-forward headers
* **toProxy**: passes the absolute URL as the `path` (useful for proxying to proxies)

### Shutdown

3 changes: 2 additions & 1 deletion lib/http-proxy/common.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ var common = exports,
url = require('url'),
extend = require('util')._extend;

var upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i;
/**
* Copies the right headers from `options` and `req` to
* `outgoing` which is then used to fire the proxied
@@ -53,7 +54,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
if (!outgoing.agent) {
outgoing.headers = outgoing.headers || {};
if (typeof outgoing.headers.connection !== 'string'
|| outgoing.headers.connection.toLowerCase() !== 'upgrade'
|| !upgradeHeader.test(outgoing.headers.connection)
) { outgoing.headers.connection = 'close'; }
}

1 change: 1 addition & 0 deletions lib/http-proxy/passes/ws-incoming.js
Original file line number Diff line number Diff line change
@@ -108,6 +108,7 @@ var passes = exports;
return i + ": " + proxyRes.headers[i];
}).join('\r\n') + '\r\n\r\n');
proxySocket.pipe(socket).pipe(proxySocket);
server.emit('proxySocket', proxySocket);
});

return proxyReq.end(); // XXX: CHECK IF THIS IS THIS CORRECT
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "http-proxy",
"version" : "1.4.3",
"version" : "1.5.0",

"repository" : {
"type" : "git",
43 changes: 43 additions & 0 deletions test/lib-http-proxy-common-test.js
Original file line number Diff line number Diff line change
@@ -59,6 +59,49 @@ describe('lib/http-proxy/common.js', function () {
expect(outgoing.headers.connection).to.eql('upgrade');
});

it('should not override agentless connection: contains upgrade', function () {
var outgoing = {};
common.setupOutgoing(outgoing,
{
agent: undefined,
target: {
host : 'hey',
hostname : 'how',
socketPath: 'are',
port : 'you',
},
headers: {'connection': 'keep-alive, upgrade'}, // this is what Firefox sets
},
{
method : 'i',
url : 'am',
headers : {'pro':'xy','overwritten':false}
});
expect(outgoing.headers.connection).to.eql('keep-alive, upgrade');
});

it('should override agentless connection: contains improper upgrade', function () {
// sanity check on upgrade regex
var outgoing = {};
common.setupOutgoing(outgoing,
{
agent: undefined,
target: {
host : 'hey',
hostname : 'how',
socketPath: 'are',
port : 'you',
},
headers: {'connection': 'keep-alive, not upgrade'},
},
{
method : 'i',
url : 'am',
headers : {'pro':'xy','overwritten':false}
});
expect(outgoing.headers.connection).to.eql('close');
});

it('should override agentless non-upgrade header to close', function () {
var outgoing = {};
common.setupOutgoing(outgoing,