https://github.com/mikeal/hostproxy
HTTP Proxy that searches for Host header and avoids any parsing
https://github.com/mikeal/hostproxy
Last synced: 2 months ago
JSON representation
HTTP Proxy that searches for Host header and avoids any parsing
- Host: GitHub
- URL: https://github.com/mikeal/hostproxy
- Owner: mikeal
- Created: 2013-04-19T19:33:45.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2017-07-11T21:52:58.000Z (almost 8 years ago)
- Last Synced: 2024-10-18T09:13:48.563Z (8 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 23
- Watchers: 6
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Pure TCP HTTP Proxy
`hostproxy` is a pure TCP proxy for HTTP. It does not fully parse HTTP, it simply searches for the `Host` header and injects other headers in to the stream.
#### API
```javascript
var hostproxy = require('hostproxy')
, net = require('net')
;hostproxy(function (host) {
if (host === 'mysite.com') return net.connect(80, 'mysite.com')
return net.connect(80, 'fallback.com')
}).listen(80)
```If no host header is present then host will be null.
```javascript
hostproxy(function (host) {
if (!host) return // returning nothing will force disconnect the client
return net.connect(80, host)
}).listen(80)
```What about adding headers?
```javascript
hostproxy(function (host, addHeader, address) {
addHeader('x-forwarded-for', address.address)
return net.connect(80, host || 'fallback.com')
}).listen(80)
```The `address` param is the return value from [socket.address()](http://nodejs.org/api/net.html#net_socket_address).