Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
204 commits
Select commit Hold shift + click to select a range
cdb4524
Merge pull request #136 from bmeck/drain-fix
indexzero Oct 22, 2011
63ac925
[refactor] core proxy logic. all tests should be passing.
Marak Oct 25, 2011
9e630da
[minor] Indentation fix
Marak Oct 25, 2011
9f92332
[refactor] Improved event handler cleanup
Marak Oct 25, 2011
c83d88e
Revert "[refactor] Improved event handler cleanup "
Oct 25, 2011
6a9751e
Merge branch 'master' of github.com:nodejitsu/node-http-proxy
Marak Nov 16, 2011
f086692
Merge branch 'master' of github.com:nodejitsu/node-http-proxy
Marak Dec 5, 2011
8d701bb
[example] Replace `sys` usages with `util`
mmalecki Oct 25, 2011
6655e01
[v0.6] Don't use `agent.appendMessage()`
mmalecki Oct 27, 2011
86b4122
[v0.6] `http.Agent` uses different structure for sockets
mmalecki Nov 2, 2011
5b52c89
[refactor] Updates to support http2 from @mikeal
indexzero Sep 10, 2011
ea7fea6
[refactor minor] Update vendor/websocket.js to be compatible with nod…
indexzero Dec 23, 2011
3828616
[refactor] Listen for `socket` events since reverseProxy.socket is no…
indexzero Dec 23, 2011
6f8ad3b
Merge branch '0.6-compatibility'
indexzero Dec 23, 2011
c81bae2
[fix minor] Correctly set x-forwarded-proto in WebSocket requests
indexzero Dec 23, 2011
5055689
[dist] Version bump. 0.8.0
indexzero Dec 23, 2011
868f7e7
fixed comment typos in examples/http/proxy-https-to-http.js and proxy…
metahack Jan 9, 2012
73e415a
Address ticket #180 here since that problem is so hard to discover wh…
drewp Feb 7, 2012
91bb2a9
Merge pull request #189 from drewp/master
Feb 12, 2012
e15db4f
fix the broken english and clarified the sentence (I hope)
drewp Mar 2, 2012
b979cb3
Merge pull request #205 from drewp/master
Marak Mar 2, 2012
7fa6599
Making README links consistent with latest project structure.
larsburgess Mar 14, 2012
a088efd
Merge pull request #208 from larsburgess/patch-1
Marak Mar 14, 2012
e9fd3f4
Whitespace fixes
coderarity Mar 28, 2012
99ee542
Re-emit 'start', 'forward' and 'end' events in RoutingProxy.
coderarity Mar 28, 2012
4f2bc58
Add documentation for listening for proxy events to prevent a common …
coderarity Mar 28, 2012
f20b374
Merge branch 'master' of github.com:nodejitsu/node-http-proxy
Marak Mar 29, 2012
fd7fcd8
[examples] Added simple load balancer example
Marak Mar 29, 2012
f1611ec
Fix problem with req.url not being not properly replaced.
coderarity Mar 28, 2012
6201328
Added example for gzip middleware using a ProxyTable.
coderarity Mar 30, 2012
5842d0e
syntax error fixed
subnetmarco Mar 30, 2012
1a014f9
Merge pull request #222 from thefosk/master
Marak Mar 30, 2012
4358a4c
finally removed hidden char
subnetmarco Mar 30, 2012
11315e6
Merge branch 'master' of https://github.com/thefosk/node-http-proxy i…
jfhbrook Mar 30, 2012
b26b434
Fix RoutingProxy hanging when there is an error
coderarity Mar 31, 2012
843901e
[doc] add missing {} to make an object
darashi Apr 3, 2012
4fc1ee8
[doc] call listen() to get the server started
darashi Apr 3, 2012
4d7eaff
Merge pull request #225 from darashi/fix-readme
jfhbrook Apr 3, 2012
ed06af9
[doc] Fix style in websockets example
jfhbrook Apr 3, 2012
5d839dd
Add tests for remapping URL properly.
coderarity Apr 11, 2012
c4d185d
prefer `target.hostname` over `target.host`
Filirom1 Apr 24, 2012
27316e2
[dist] Update author field for consistency
coderarity May 7, 2012
f223ce8
Merge pull request #216 from CodeRarity/master
coderarity May 10, 2012
0532995
Implement RoutingProxy.prototype.remove
tellnes May 17, 2012
ca37ad7
[fix] x-forwarded-proto sets properly
ryanstevens May 22, 2012
b584773
[misc] Updating the changelog. Close #137
cronopio May 31, 2012
df650d1
[minor fix] delete white space
cronopio May 31, 2012
64c9747
Merge pull request #218 from CodeRarity/proxy-table-fix
coderarity Jun 5, 2012
e9a3a30
[misc] changelog updated to version 0.8.1
cronopio Jun 5, 2012
27fa708
Merge pull request #256 from nodejitsu/changelog
indexzero Jun 5, 2012
45d67f4
[tests] used socket.io 0.6.17 fixed version for tests
cronopio Jun 5, 2012
81f6095
[dist] Version bump 0.8.1
cronopio Jun 5, 2012
0933f1c
Fix bug: x-forwarded-proto set incorrectly
rampr Jun 19, 2012
ccd8f84
Merge pull request #266 from rampr/master
jfhbrook Jun 19, 2012
06e78f2
adding support for setting the host
shapeshed Jun 20, 2012
415d4ed
match style requested by @cronopio
shapeshed Jun 20, 2012
bf7e328
[fix] Changed require('util') to require('util') for compatibility wi…
blakmatrix Jun 25, 2012
fd16aeb
Merge pull request #270 from node-migrator-bot/clean
mmalecki Jun 25, 2012
0b6c7f5
add "Using two certificiates" to the https section of the readme.md
jfromaniello Jul 3, 2012
4ae7a5b
[refactor] Rewrite tests to use saner vows idioms. Update tests to us…
indexzero Jul 21, 2012
e2dc7f9
[refactor test] Finish removing old test code.
indexzero Jul 22, 2012
55286a7
[fix api] Optimize lookups in the ProxyTable. Ensure that RoutingProx…
indexzero Jul 22, 2012
828dbeb
[refactor test] Add support for `http*-to-http*` testing from CLI arg…
indexzero Jul 22, 2012
7e854d7
[refactor tests] Finished refactoring tests to support `ws*-to-ws*` t…
indexzero Jul 22, 2012
54f8371
Merge pull request #268 from shapeshed/patch-1
indexzero Jul 22, 2012
1cc1f90
Merge pull request #275 from jfromaniello/patch-1
indexzero Jul 22, 2012
04ce49c
Whitespace fixes.
coderarity Apr 13, 2012
0273958
Use changeOrigin for proxyRequest.
coderarity Apr 13, 2012
f28c62c
Merge pull request #235 from Filirom1/patch-1
indexzero Jul 22, 2012
02b914d
Merge pull request #246 from tellnes/proxy-remove
indexzero Jul 22, 2012
4999b20
Merge branch '0.8.2'
indexzero Jul 22, 2012
46c184c
Merge pull request #221 from coderarity/gzip-middleware-proxytable-ex…
indexzero Jul 22, 2012
36226da
[dist] Complete JSHint compliance except for `too many var statements`
indexzero Jul 22, 2012
2d75510
[dist] Remove out-dated docco docs
indexzero Jul 22, 2012
29e6e74
[test] Add .travis.yml file for Travis CI.
AvianFlu Jul 22, 2012
6753951
[doc] Minor formatting updates to README.md
indexzero Jul 22, 2012
13c34d0
[dist] Version bump. 0.8.2
indexzero Jul 22, 2012
0d00b06
[fix] `destroy()` websockets in case of an error
mmalecki Jul 24, 2012
24b8406
Fix socket leaks when FIN packet isn't responded to
piscisaureus Jul 24, 2012
89459bf
If supplied pass changeOrigin option through to HttpProxy instance if…
1stvamp Jul 25, 2012
82da853
Merge pull request #285 from 1stvamp/pass-change-origin-from-routing-…
indexzero Jul 26, 2012
fd648a5
[fix test] Fix examples to use newest version of socket.io and helper…
indexzero Jul 26, 2012
c4a7b15
[fix] Suppress EADDRINUSE errors from `test/examples-test.js` since w…
indexzero Jul 26, 2012
a454666
[fix] Ignore npm version errors when installing dependencies for exam…
indexzero Jul 26, 2012
1783ab0
[fix] Dont use `-i` when running vows because it supresses `--target=…
indexzero Jul 26, 2012
812868d
[minor] Remove `setEncoding` on incoming socket
mmalecki Aug 10, 2012
cee27fe
[minor doc] Correct comment
mmalecki Aug 10, 2012
4f6387c
[test] Add `node v0.9` testing, test all branches
mmalecki Aug 10, 2012
850171c
If HTTP 1.1 is used and backend doesn't return 'Connection' header, e…
Kami Aug 17, 2012
1db9542
Fix installation instructions: s/http/https/
janl Aug 27, 2012
bf04bbd
Merge pull request #302 from janl/patch-1
dscape Aug 27, 2012
a64cec0
Added travis build status
peters Sep 13, 2012
698b01d
[fix] spdy should look like https when forwarding (until we get a cli…
bmeck Sep 20, 2012
a89a5b8
[dist] v0.8.3
bmeck Sep 20, 2012
e925e49
Merge pull request #308 from peters/patch-1
mmalecki Sep 24, 2012
eafdc74
[refactor] Pass all options to `Agent` constructor
mmalecki Sep 27, 2012
2e7d8a8
[fix] Partial fix for rejecting self-signed certs in tests
mmalecki Sep 27, 2012
4c8e1d9
[docs] options
yawnt Oct 14, 2012
d4cb9da
[docs] more options
yawnt Oct 14, 2012
213e03c
[fix] function
yawnt Oct 15, 2012
1df2b30
Merge pull request #315 from yawnt/options-doc
blakmatrix Oct 15, 2012
5df6e7b
http-proxy: emit websocket:start
indutny Oct 23, 2012
ebfdbed
Merge pull request #320 from indutny/master
mmalecki Oct 23, 2012
4d7e8a8
[dist] Bump version to 0.8.4
mmalecki Oct 23, 2012
a487dc9
lib: allow overriding maxSockets
indutny Oct 25, 2012
3d61877
Merge pull request #323 from indutny/fix-maciej-issue
mmalecki Oct 26, 2012
fefbf04
[test] Upgrade `common.js` from node core
mmalecki Oct 28, 2012
3531fd6
[test] Make global detection work with older node versions
mmalecki Oct 28, 2012
74ec175
[test] Kill child process when exiting test runner
mmalecki Oct 28, 2012
41c9a9c
[test] Run core tests on `npm test`
mmalecki Oct 28, 2012
9042665
[test] Stop testing on `node v0.9`, tests timeout
mmalecki Oct 28, 2012
886a395
[test] Delete invalid core test
mmalecki Oct 29, 2012
b8c27ed
[fix] Correctly kill test processes
mmalecki Oct 29, 2012
8a88774
[fix] Convert strings to numbers if possible in `.createServer`
Southern Nov 6, 2012
03dbe11
add "with custom server logic" to the "Proxying WebSockets" section o…
sergioramos Nov 8, 2012
22639b3
[dist] Bump version to 0.8.5
mmalecki Nov 16, 2012
0fd5884
http-proxy: 304 responses should emit 'end' too
indutny Nov 21, 2012
8b3cfda
Merge pull request #337 from indutny/feature-304-end
indexzero Nov 29, 2012
2bd9cd9
[bench] Remove silly "benchmarks"
mmalecki Nov 30, 2012
6797a27
[bench] Add a benchmark for websockets throughput
mmalecki Nov 30, 2012
b81d9b7
[dist] Update `devDependencies`
mmalecki Nov 30, 2012
7bc1a62
[bench] More exact size display
mmalecki Nov 30, 2012
2a61ec8
[fix] Handle socket errors
mmalecki Dec 12, 2012
6cd78f6
[dist] Bump version to 0.8.6
mmalecki Dec 21, 2012
edfe869
[fix] Handle errors on request object
mmalecki Dec 21, 2012
223eacd
[fix] Don't remove `error` listener after response ends
mmalecki Dec 22, 2012
26d3646
[dist] Bump version to 0.8.7
mmalecki Dec 22, 2012
15afc23
fix 'this' reference in routing proxy listener bindings
Jan 13, 2013
d2888c8
Fix for retaining large slab buffers in node core
Jan 24, 2013
43e5f33
fixed issue #364 'proxyError' event emitted twice
erasmospunk Feb 10, 2013
3b84e27
remove offending code, final fix for issue #364
erasmospunk Feb 12, 2013
ee6bbe0
Change wording for handling websocket proxy events
itsjamie Feb 22, 2013
603106a
Re-added previous description
itsjamie Feb 22, 2013
c686ac7
Merge pull request #349 from jamie-stackhouse/patch-1
indexzero Mar 9, 2013
8b38c99
Merge pull request #374 from erasmospunk/master
indexzero Mar 9, 2013
025adc2
Merge pull request #365 from adjohnson916/master
indexzero Mar 9, 2013
916d44e
Routing Proxy was not sending x-forward-*. Fixing It...
otaviojr Dec 6, 2012
1332409
working on x-forwarded-for
otaviojr Dec 7, 2012
31fc94a
working on x-forwarded-for
otaviojr Dec 7, 2012
8d87399
cleanning
otaviojr Dec 7, 2012
9672b99
cleanning
otaviojr Dec 7, 2012
83fbd42
Added simple round robin example with websocket support
oost Nov 26, 2012
64efa7f
Added comments
oost Nov 26, 2012
deca756
[doc fix] Add undefined var in example.
indexzero Mar 9, 2013
013cb2e
[fix] Ensure `response.headers.location` is defined. Fixes #276.
indexzero Mar 9, 2013
2055d0c
memory leak fix in closing of the scokets
Jul 30, 2012
a681493
[fix minor] Prevent crashes from attempting to remove listeners more …
indexzero Mar 9, 2013
c6da760
Revert "[fix minor] Prevent crashes from attempting to remove listene…
indexzero Mar 9, 2013
eee6bab
Merge pull request #332 from ramitos/patch-1
indexzero Mar 9, 2013
ffe74ed
- support unix donain sockets and windows named pipes (socketPath) on…
yosefd Jul 29, 2012
ecb5472
Add tests for headers bug fixes
gilad61 Jul 31, 2012
28a3b0a
[fix] Remove special case handling of `304` responses since it was fi…
indexzero Mar 9, 2013
af9eb06
Merge pull request #298 from Kami/connection_keep_alive_on_1_1
indexzero Mar 9, 2013
ef66833
Fix truncated chunked responses
jpetazzo Nov 4, 2012
ba65a48
Fix typo which slipped in during patch clean-up
jpetazzo Nov 4, 2012
440013c
[fix doc] Fix bad variable reference in `README.md`.
indexzero Mar 9, 2013
9cecd97
[minor] s/function(/function (/ s/){/) {/
indexzero Mar 9, 2013
4c130f5
Allow event observers to access upstream response headers and data.
colinmollenhour Dec 29, 2012
3b86a7a
Add 'proxyResponse' event so observer can modify response headers or …
colinmollenhour Jan 6, 2013
b1c4bd6
Remove data event that is not needed after-all.
colinmollenhour Jan 7, 2013
4c1a2c1
[fix] Make options immutable in `RoutingProxy`. Fixes #248.
indexzero Mar 9, 2013
3130665
[fix] Emit `notFound` event when ProxyTable location does not exist. …
indexzero Mar 9, 2013
6a278b3
[fix] http-proxy should not modify the protocol in redirect request f…
indexzero Mar 9, 2013
a89e2f2
[fix] Do not use "Transfer-Encoding: chunked" header for proxied DELE…
indexzero Mar 9, 2013
9be0af3
[fix] Set "content-length" header to "0" if it is not already set on …
indexzero Mar 9, 2013
476cbe7
[minor] Move private helper to end of file.
indexzero Mar 9, 2013
89d43c2
Added timeout option and test to test new timeout parameter, added re…
pdoran Feb 3, 2013
2c36507
problem: don't want to run my server as root to bind to privileged po…
Feb 27, 2012
10f6b05
add support for loading CA bundles
Feb 27, 2012
46b078a
pathnameOnly flag added. Ignores hostname and applies routing table …
mikkel Mar 6, 2013
a1607c1
pathnameOnly option documented in the Readme.md
mikkel Mar 6, 2013
5e6be6c
[doc] added comments to pathnameOnly block.
mikkel Mar 6, 2013
5d515e4
[api test] Manually merge #195 from @tglines since that fork was dele…
indexzero Mar 9, 2013
ea0587a
[minor] Small whitespace compliance.
indexzero Mar 9, 2013
ad21310
[dist] Update `devDependencies`
indexzero Mar 9, 2013
133115c
[doc dist] Update CHANGELOG.md for `v0.9.0`.
indexzero Mar 9, 2013
c68e038
[dist] Version bump. 0.9.0
indexzero Mar 9, 2013
c78356e
[breaking] Ensure that `webSocketProxyError` also receives the error …
indexzero Mar 9, 2013
ea5e214
[dist doc] Updated CHANGELOG.md for `v0.9.1`
indexzero Mar 9, 2013
701dc69
[dist] Version bump. 0.9.1
indexzero Mar 9, 2013
c9b6895
Fixing the if statement as it lead to 'TypeError: Parameter 'url' mus…
subnetmarco Mar 15, 2013
35ba0db
Harmon messsage
Mar 16, 2013
4e42354
Harmon messsage
Mar 16, 2013
3ebc795
Merge pull request #384 from No9/master
indexzero Mar 16, 2013
2620f06
[fix breaking] Emit the `proxyResponse` event on the HttpProxy instan…
indexzero Mar 18, 2013
ea10bb2
Merge pull request #383 from thefosk/master
indexzero Mar 18, 2013
4335f49
Merge pull request #385 from nodejitsu/breaking-proxy-response
indexzero Mar 18, 2013
8665f3c
[dist] Update CHANGELOG.md
indexzero Mar 18, 2013
71183bf
[dist] Version bump. 0.10.0
indexzero Mar 18, 2013
3763dc9
Merge pull request #370 from jmatthewsr-ms/master
indexzero Apr 9, 2013
9c13ad4
[dist] Version bump. 0.10.1
indexzero Apr 12, 2013
a29b5e8
Correct keep-alive responses to HTTP 1.0 clients.
GUI Apr 18, 2013
daf53bd
Don't test raw HTTP 1.0 requests over HTTPS.
GUI Apr 19, 2013
98f5c46
Merge pull request #407 from GUI/master
indexzero Apr 21, 2013
985025c
Add headers on 'handshake'
Apr 8, 2013
59b71c0
[minor] Style compliance. Fixes #402.
indexzero Apr 21, 2013
7fc39d7
[minor] Strip trailing whitespace.
indexzero Apr 21, 2013
de0928f
[dist] Version bump. 0.10.2
indexzero Apr 21, 2013
f5e1844
Pass default certs to SNICallback example
Raynos May 10, 2013
5ff2b6e
Merge pull request #419 from Raynos/patch-1
indexzero Jun 15, 2013
e1d384e
[fix] Respect `maxSockets` from `target` options in `RoutingProxy`
mmalecki Jun 20, 2013
2fd748f
[dist] Bump version to 0.10.3
mmalecki Jun 20, 2013
ebbba73
[test] Test on newer version of node
mmalecki Jun 20, 2013
611a1b1
[fix] add 0.10 link, fixes #459
yawnt Sep 17, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
node_js:
- 0.8
- "0.10"
- "0.11"

notifications:
email:
- travis@nodejitsu.com
irc: "irc.freenode.org#nodejitsu"
65 changes: 65 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,70 @@
## ChangeLog for: node-http-proxy

## Version 0.10.0 - 3/18/2013

- Breaking change: `proxyResponse` events are emitted on the `HttpProxy` or `RoutingProxy` instances as originally was intended in `0.9.x`.

## Version 0.9.1 - 3/9/2013

- Ensure that `webSocketProxyError` and `proxyError` both receive the error (indexzero).

## Version 0.9.0 - 3/9/2013
- Fix #276 Ensure response.headers.location is defined (indexzero)
- Fix #248 Make options immutable in RoutingProxy (indexzero)
- Fix #359 Do not modify the protocol in redirect request for external sites. (indexzero)
- Fix #373 Do not use "Transfer-Encoding: chunked" header for proxied DELETE requests with no "Content-Length" header. (indexzero)
- Fix #338 Set "content-length" header to "0" if it is not already set on DELETE requests. (indexzero)
- Updates to README.md and Examples (ramitos, jamie-stackhouse, oost, indexzero)
- Fixes to ProxyTable and Routing Proxy (adjohnson916, otavoijr)
- New API for ProxyTable (mikkel, tglines)
- Add `options.timeout` for specifying socket timeouts (pdoran)
- Improve bin/node-http-proxy (niallo)
- Don't emit `proxyError` twice (erasmospunk)
- Fix memory leaks in WebSocket proxying
- Support UNIX Sockets (yosefd)
- Fix truncated chunked respones (jpetazzo)
- Allow upstream listeners to get `proxyResponse` (colinmollenhour)

## Version 0.8.1 - 6/5/2012
- Fix re-emitting of events in RoutingProxy (coderarity)
- New load balancer and middleware examples (marak)
- Docs updated including changelog (lot of gently people)

## Version 0.8.0 - 12/23/2011
- Improve support and tests for url segment routing (maxogden)
- Fix aborting connections when request close (c4milo)
- Avoid 'Transfer-Encoding' on HTTP/1.0 clients (koichik).
- Support for Node.js 0.6.x (mmalecki)

## Version 0.7.3 - 10/4/2011
- Fix setting x-forwarded headers (jesusabdullah)
- Updated examples (AvianFlu)

## Version 0.7.0 - 9/10/2011
- Handles to every throw-able resume() call (isaacs)
- Updated tests, README and package.json (indexzero)
- Added HttpProxy.close() method (indexzero)

## Version 0.6.6 - 8/31/2011
- Add more examples (dominictarr)
- Use of 'pkginfo' (indexzero)
- Handle cases where res.write throws (isaacs)
- Handles to every throw-able res.end call (isaacs)

## Version 0.5.11 - 6/21/2011
- Add more examples with WebSockets (indexzero)
- Update the documentation (indexzero)

## Version 0.5.7 - 5/19/2011
- Fix to README related to markup and fix some examples (benatkin)
- Improve WebSockets handling (indexzero)
- Improve WebSockets tests (indexzero)
- Improve https tests (olauzon)
- Add devDependencies to package.json (olauzon)
- Add 'proxyError' event (indexzero)
- Add 'x-forwarded-{port|proto}' headers support (indexzero)
- Keep-Alive connection supported (indexzero)

## Version 0.5.0 - 4/15/2011
- Remove winston in favor of custom events (indexzero)
- Add x-forwarded-for Header (indexzero)
Expand Down
222 changes: 210 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# node-http-proxy
# node-http-proxy [![Build Status](https://secure.travis-ci.org/nodejitsu/node-http-proxy.png)](http://travis-ci.org/nodejitsu/node-http-proxy)

<img src="http://i.imgur.com/8fTt9.png" />

Expand All @@ -18,14 +18,17 @@
* Written entirely in Javascript
* Easy to use API


node-http-proxy is `<= 0.8.x` compatible, if you're looking for a `>= 0.10` compatible version please check [caronte](https://github.com/nodejitsu/node-http-proxy/tree/caronte)

### When to use node-http-proxy

Let's suppose you were running multiple http application servers, but you only wanted to expose one machine to the internet. You could setup node-http-proxy on that one machine and then reverse-proxy the incoming http requests to locally running services which were not exposed to the outside network.

### Installing npm (node package manager)

```
curl http://npmjs.org/install.sh | sh
curl https://npmjs.org/install.sh | sh
```

### Installing node-http-proxy
Expand Down Expand Up @@ -202,6 +205,24 @@ var options = {

Notice here that I have not included paths on the individual domains because this is not possible when using only the HTTP 'Host' header. Care to learn more? See [RFC2616: HTTP/1.1, Section 14.23, "Host"][4].

### Proxy requests using a 'Pathname Only' ProxyTable

If you dont care about forwarding to different hosts, you can redirect based on the request path.

``` js
var options = {
pathnameOnly: true,
router: {
'/wiki': '127.0.0.1:8001',
'/blog': '127.0.0.1:8002',
'/api': '127.0.0.1:8003'
}
}
```

This comes in handy if you are running separate services or applications on separate paths. Note, using this option disables routing by hostname entirely.


### Proxy requests with an additional forward proxy
Sometimes in addition to a reverse proxy, you may want your front-facing server to forward traffic to another location. For example, if you wanted to load test your staging environment. This is possible when using node-http-proxy using similar JSON-based configuration to a proxy table:

Expand All @@ -217,6 +238,30 @@ proxyServerWithForwarding.listen(80);

The forwarding option can be used in conjunction with the proxy table options by simply including both the 'forward' and 'router' properties in the options passed to 'createServer'.

### Listening for proxy events
Sometimes you want to listen to an event on a proxy. For example, you may want to listen to the 'end' event, which represents when the proxy has finished proxying a request.

``` js
var httpProxy = require('http-proxy');

var server = httpProxy.createServer(function (req, res, proxy) {
var buffer = httpProxy.buffer(req);

proxy.proxyRequest(req, res, {
host: '127.0.0.1',
port: 9000,
buffer: buffer
});
});

server.proxy.on('end', function () {
console.log("The request was proxied.");
});

server.listen(8000);
```

It's important to remember not to listen for events on the proxy object in the function passed to `httpProxy.createServer`. Doing so would add a new listener on every request, which would end up being a disaster.

## Using HTTPS
You have all the full flexibility of node-http-proxy offers in HTTPS as well as HTTP. The two basic scenarios are: with a stand-alone proxy server or in conjunction with another HTTPS server.
Expand Down Expand Up @@ -267,6 +312,70 @@ http.createServer(function (req, res) {
}).listen(8000);
```

### Using two certificates

Suppose that your reverse proxy will handle HTTPS traffic for two different domains `fobar.com` and `barbaz.com`.
If you need to use two different certificates you can take advantage of [Server Name Indication](http://en.wikipedia.org/wiki/Server_Name_Indication).

``` js
var https = require('https'),
path = require("path"),
fs = require("fs"),
crypto = require("crypto");

//
// generic function to load the credentials context from disk
//
function getCredentialsContext (cer) {
return crypto.createCredentials({
key: fs.readFileSync(path.join(__dirname, 'certs', cer + '.key')),
cert: fs.readFileSync(path.join(__dirname, 'certs', cer + '.crt'))
}).context;
}

//
// A certificate per domain hash
//
var certs = {
"fobar.com": getCredentialsContext("foobar"),
"barbaz.com": getCredentialsContext("barbaz")
};

//
// Proxy options
//
var options = {
https: {
SNICallback: function (hostname) {
return certs[hostname];
},
cert: myCert,
key: myKey,
ca: [myCa]
},
hostnameOnly: true,
router: {
'fobar.com': '127.0.0.1:8001',
'barbaz.com': '127.0.0.1:8002'
}
};

//
// Create a standalone HTTPS proxy server
//
httpProxy.createServer(options).listen(8001);

//
// Create the target HTTPS server
//
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('hello https\n');
res.end();
}).listen(8000);

```

### Proxying to HTTPS from HTTPS
Proxying from HTTPS to HTTPS is essentially the same as proxying from HTTPS to HTTP, but you must include the `target` option in when calling `httpProxy.createServer` or instantiating a new instance of `HttpProxy`.

Expand Down Expand Up @@ -325,8 +434,31 @@ httpProxy.createServer(
).listen(8000);
```

A regular request we receive is to support the modification of html/xml content that is returned in the response from an upstream server.

[Harmon](https://github.com/No9/harmon/) is a stream based middleware plugin that is designed to solve that problem in the most effective way possible.

## Proxying WebSockets
Websockets are handled automatically when using `httpProxy.createServer()`, but if you want to use it in conjunction with a stand-alone HTTP + WebSocket (such as [socket.io][5]) server here's how:
Websockets are handled automatically when using `httpProxy.createServer()`, however, if you supply a callback inside the createServer call, you will need to handle the 'upgrade' proxy event yourself. Here's how:

```js

var options = {
....
};

var server = httpProxy.createServer(
callback/middleware,
options
);

server.listen(port, function () { ... });
server.on('upgrade', function (req, socket, head) {
server.proxy.proxyWebSocketRequest(req, socket, head);
});
```

If you would rather not use createServer call, and create the server that proxies yourself, see below:

``` js
var http = require('http'),
Expand All @@ -335,11 +467,12 @@ var http = require('http'),
//
// Create an instance of node-http-proxy
//
var proxy = new httpProxy.HttpProxy(
target: {
host: 'localhost',
port: 8000
});
var proxy = new httpProxy.HttpProxy({
target: {
host: 'localhost',
port: 8000
}
});

var server = http.createServer(function (req, res) {
//
Expand All @@ -348,12 +481,42 @@ var server = http.createServer(function (req, res) {
proxy.proxyRequest(req, res);
});

server.on('upgrade', function(req, socket, head) {
server.on('upgrade', function (req, socket, head) {
//
// Proxy websocket requests too
//
proxy.proxyWebSocketRequest(req, socket, head);
});

server.listen(8080);
```

### with custom server logic

``` js
var httpProxy = require('http-proxy')

var server = httpProxy.createServer(function (req, res, proxy) {
//
// Put your custom server logic here
//
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 9000
});
})

server.on('upgrade', function (req, socket, head) {
//
// Put your custom server logic here
//
server.proxy.proxyWebSocketRequest(req, socket, head, {
host: 'localhost',
port: 9000
});
});

server.listen(8080);
```

### Configuring your Socket limits
Expand All @@ -363,6 +526,12 @@ By default, `node-http-proxy` will set a 100 socket limit for all `host:port` pr
1. By passing the `maxSockets` option to `httpProxy.createServer()`
2. By calling `httpProxy.setMaxSockets(n)`, where `n` is the number of sockets you with to use.

## POST requests and buffering

express.bodyParser will interfere with proxying of POST requests (and other methods that have a request
body). With bodyParser active, proxied requests will never send anything to the upstream server, and
the original client will just hang. See https://github.com/nodejitsu/node-http-proxy/issues/180 for options.

## Using node-http-proxy from the command line
When you install this package with npm, a node-http-proxy binary will become available to you. Using this binary is easy with some simple options:

Expand All @@ -384,6 +553,35 @@ options:

If you have a suggestion for a feature currently not supported, feel free to open a [support issue][6]. node-http-proxy is designed to just proxy http requests from one server to another, but we will be soon releasing many other complimentary projects that can be used in conjunction with node-http-proxy.

## Options

### Http Proxy

`createServer()` supports the following options

```javascript
{
forward: { // options for forward-proxy
port: 8000,
host: 'staging.com'
},
target : { // options for proxy target
port : 8000,
host : 'localhost',
};
source : { // additional options for websocket proxying
host : 'localhost',
port : 8000,
https: true
},
enable : {
xforward: true // enables X-Forwarded-For
},
changeOrigin: false, // changes the origin of the host header to the target URL
timeout: 120000 // override the default 2 minute http socket timeout value in milliseconds
}
```

## Run Tests
The test suite is designed to fully cover the combinatoric possibilities of HTTP and HTTPS proxying:

Expand Down Expand Up @@ -426,9 +624,9 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

[0]: http://nodejitsu.com
[1]: https://github.com/nodejitsu/node-http-proxy/blob/master/examples/web-socket-proxy.js
[2]: https://github.com/nodejitsu/node-http-proxy/blob/master/examples/basic-proxy-https.js
[3]: https://github.com/nodejitsu/node-http-proxy/tree/v0.5.0/examples
[1]: https://github.com/nodejitsu/node-http-proxy/blob/master/examples/websocket/websocket-proxy.js
[2]: https://github.com/nodejitsu/node-http-proxy/blob/master/examples/http/proxy-https-to-http.js
[3]: https://github.com/nodejitsu/node-http-proxy/tree/master/examples
[4]: http://www.ietf.org/rfc/rfc2616.txt
[5]: http://socket.io
[6]: http://github.com/nodejitsu/node-http-proxy/issues
Loading