proxy for the masses, reimplementation of node-http-proxy from the ground up for koa 2.
Install
npm i -S koaproxy
koaproxy
is an HTTP programmable proxying library that supports
websockets and is tailored for koa 2 (async / await). It is suitable for
implementing components such as reverse proxies and load balancers.
Roadmap
This library is currently in a state of rewrite. Some of the documentation has not yet been rewritten. Stay tuned.
- Rewrite with ES modules as es-http-proxy - Done
- Get all tests passing with ES6+ mocha - Done
- Write koaproxy
- async / await friendly promise based
- Rewrite docs
Table of Contents
- Core Concept
- Use Cases
- Options
- Listening for proxy events
- Shutdown
- Miscellaneous
- Contributing and Issues
- Tests
Core Concept
A new proxy is created by calling createProxyServer
and passing
an options
object as argument (valid properties are available here)
var httpProxy = ; var proxy = httpProxy; // See (†)
†Unless listen(..) is invoked on the object, this does not create a webserver. See below.
An object will be returned with four methods:
- web
req, res, [options]
(used for proxying regular HTTP(S) requests) - ws
req, socket, head, [options]
(used for proxying WS(S) requests) - 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)
It is then possible to proxy requests by calling these functions
http;
Errors can be listened on either using the Event Emitter API
proxy;
or using the callback API
proxy;
When a request is proxied it follows two different pipelines (available here)
which apply transformations to both the req
and res
object.
The first pipeline (ingoing) is responsible for the creation and manipulation of the stream that connects your client to the target.
The second pipeline (outgoing) is responsible for the creation and manipulation of the stream that, from your target, returns data
to the client.
Use Cases
Setup a basic stand-alone proxy server
var http = httpProxy = ;//// Create your proxy server and set the target in the options.//httpProxy; // See (†) //// Create your target server//http;
†Invoking listen(..) triggers the creation of a web server. Otherwise, just the proxy instance is created.
Setup a stand-alone proxy server with custom server logic
This example show how you can proxy a request using your own HTTP server and also you can put your own logic to handle the request.
var http = httpProxy = ; //// Create a proxy server with custom application logic//var proxy = httpProxy; //// Create your custom server and just call `proxy.web()` to proxy// a web request to the target passed in the options// also you can use `proxy.ws()` to proxy a websockets request//var server = http; consoleserver;
Setup a stand-alone proxy server with proxy request header re-writing
This example shows how you can proxy a request using your own HTTP server that modifies the outgoing proxy request by adding a special header.
var http = httpProxy = ; //// Create a proxy server with custom application logic//var proxy = httpProxy; // To modify the proxy connection before data is sent, you can listen// for the 'proxyReq' event. When the event is fired, you will receive// the following arguments:// (http.ClientRequest proxyReq, http.IncomingMessage req,// http.ServerResponse res, Object options). This mechanism is useful when// you need to modify the proxy request before the proxy connection// is made to the target.//proxy; var server = http; consoleserver;
Modify a response from a proxied server
Sometimes when you have received a HTML/XML document from the server of origin you would like to modify it before forwarding it on.
Harmon allows you to do this in a streaming style so as to keep the pressure on the proxy to a minimum.
Setup a stand-alone proxy server with latency
var http = httpProxy = ; //// Create a proxy server with latency//var proxy = httpProxy; //// Create your server that makes an operation that waits a while// and then proxies the request//http; //// Create your target server//http;
Using HTTPS
You can activate the validation of a secure SSL certificate to the target connection (avoid self signed certs), just set secure: true
in the options.
HTTPS -> HTTP
//// Create the HTTPS proxy server in front of a HTTP server//httpProxy;
HTTPS -> HTTPS
//// Create the proxy server listening on port 443//httpProxy;
Proxying WebSockets
You can activate the websocket support for the proxy using ws:true
in the options.
//// Create a proxy server for websockets//httpProxy;
Also you can proxy the websocket requests just calling the ws(req, socket, head)
method.
//// Setup our server to proxy standard HTTP requests//var proxy = target: host: 'localhost' port: 9015 ;var proxyServer = http; //// Listen to the `upgrade` event and proxy the// WebSocket requests as well.//proxyServer; proxyServer;
Options
httpProxy.createProxyServer
supports the following options:
- target: url string to be parsed with the url module
- forward: url string to be parsed with the url module
- agent: object to be passed to http(s).request (see Node's https agent and http agent objects)
- ssl: object to be passed to https.createServer()
- ws: true/false, if you want to proxy websockets
- xfwd: true/false, adds x-forward headers
- secure: true/false, if you want to verify the SSL Certs
- toProxy: true/false, passes the absolute URL as the
path
(useful for proxying to proxies) - prependPath: true/false, Default: true - specify whether you want to prepend the target's path to the proxy path
- ignorePath: true/false, Default: false - specify whether you want to ignore the proxy path of the incoming request (note: you will have to append / manually if required).
- localAddress: Local interface string to bind for outgoing connections
- changeOrigin: true/false, Default: false - changes the origin of the host header to the target URL
- auth: Basic authentication i.e. 'user:password' to compute an Authorization header.
- hostRewrite: rewrites the location hostname on (301/302/307/308) redirects.
- autoRewrite: rewrites the location host/port on (301/302/307/308) redirects based on requested host/port. Default: false.
- protocolRewrite: rewrites the location protocol on (301/302/307/308) redirects to 'http' or 'https'. Default: null.
- headers: object with extra headers to be added to target requests.
NOTE:
options.ws
and options.ssl
are optional.
options.target
and options.forward
cannot both be missing
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
Listening for proxy events
error
: The error event is emitted if the request to the target fail. We do not do any error handling of messages passed between client and proxy, and messages passed between proxy and target, so it is recommended that you listen on errors and handle them.proxyReq
: This event is emitted before the data is sent. It gives you a chance to alter the proxyReq request object. Applies to "web" connectionsproxyReqWs
: This event is emitted before the data is sent. It gives you a chance to alter the proxyReq request object. Applies to "websocket" connectionsproxyRes
: This event is emitted if the request to the target got a response.open
: This event is emitted once the proxy websocket was created and piped into the target websocket.close
: This event is emitted once the proxy websocket was closed.- (DEPRECATED)
proxySocket
: Deprecated in favor ofopen
.
var httpProxy = ;// Error example//// Http Proxy Server with bad target//var proxy = httpProxy; proxy; //// Listen for the `error` event on `proxy`.proxy; //// Listen for the `proxyRes` event on `proxy`.//proxy; //// Listen for the `open` event on `proxy`.//proxy; //// Listen for the `close` event on `proxy`.//proxy;
Shutdown
- When testing or running server within another program it may be necessary to close the proxy.
- This will stop the proxy from accepting new connections.
var proxy = target: host: 'localhost' port: 1337 ; proxy;
Miscellaneous
ProxyTable API
A proxy table API is available through this add-on module, which lets you define a set of rules to translate matching routes to target routes that the reverse proxy will talk to.
Test
$ npm test
Logo
Logo created by Diego Pasquali
Contributing and Issues
- Search on Google/Github
- If you can't find anything, open an issue
- If you feel comfortable about fixing the issue, fork the repo
- Commit to your local branch (which must be different from
master
) - Submit your Pull Request (be sure to include tests and update documentation)
TEST
Unit tests output for current release:
TOC
- lib/es-http-proxy/common.js
- lib/es-http-proxy/passes/web.js
- #createProxyServer.web() using own http server
- lib/es-http-proxy/passes/web-outgoing.js
- lib/es-http-proxy/passes/ws-incoming.js
- ProxyServer
- lib/es-http-proxy.js
- #createProxyServer
- #createProxyServer with forward options and using web-incoming passes
- #createProxyServer using the web-incoming passes
- #createProxyServer() method with error response
- #createProxyServer setting the correct timeout value
- #createProxyServer using the ws-incoming passes
- HTTPS #createProxyServer
- es-http-proxy examples
lib/es-http-proxy/common.js
#setupOutgoing
should exist.
return should;
should be a function.
return setupOutgoingshouldbe;
should not override agentless upgrade header.
var outgoing = {};common;0 _chaiexpectoutgoingheadersconnectionto;
should not override agentless connection: contains upgrade.
var outgoing = {};common;0 _chaiexpectoutgoingheadersconnectionto;
should override agentless connection: contains improper upgrade.
// sanity check on upgrade regexvar outgoing = {};common;0 _chaiexpectoutgoingheadersconnectionto;
should override agentless non-upgrade header to close.
var outgoing = {};common;0 _chaiexpectoutgoingheadersconnectionto;
should set the agent to false if none is given.
var outgoing = {};common;0 _chaiexpectoutgoingagentto;
set the port according to the protocol.
var outgoing = {};common;0 _chaiexpectoutgoinghostto;0 _chaiexpectoutgoinghostnameto;0 _chaiexpectoutgoingsocketPathto;0 _chaiexpectoutgoingagentto;0 _chaiexpectoutgoingmethodto;0 _chaiexpectoutgoingpathto;0 _chaiexpectoutgoingheadersproto;0 _chaiexpectoutgoingportto;
should keep the original target path in the outgoing path.
var outgoing = {};common;0 _chaiexpectoutgoingpathto;
should keep the original forward path in the outgoing path.
var outgoing = {};common;0 _chaiexpectoutgoingpathto;
should properly detect https/wss protocol without the colon.
var outgoing = {};common;0 _chaiexpectoutgoingportto;
should not prepend the target path to the outgoing path with prependPath = false.
var outgoing = {};common;0 _chaiexpectoutgoingpathto;
should properly join paths.
var outgoing = {};common;0 _chaiexpectoutgoingpathto;
should not modify the query string.
var outgoing = {};common;0 _chaiexpectoutgoingpathto;
should correctly format the toProxy URL.
var outgoing = {};var google = 'https://google.com';common;0 _chaiexpectoutgoingpathto;
should not replace : to :\ when no https word before.
var outgoing = {};var google = 'https://google.com:/join/join.js';common;0 _chaiexpectoutgoingpathto;
should not replace : to :\ when no http word before.
var outgoing = {};var google = 'http://google.com:/join/join.js';common;0 _chaiexpectoutgoingpathto;
should pass through https client parameters.
var outgoing = {};common;0 _chaiexpectoutgoingpfx;0 _chaiexpectoutgoingkey;0 _chaiexpectoutgoingpassphrase;0 _chaiexpectoutgoingcert;0 _chaiexpectoutgoingca;0 _chaiexpectoutgoingciphers;0 _chaiexpectoutgoingsecureProtocol;
outgoing
should exist.
return should;
should be an object.
return outgoingshouldbe;
#host
should exist.
return should;
should be a string.
return propshouldbe;
should equal hey.
return propshould;
#hostname
should exist.
return should;
should be a string.
return propshouldbe;
should equal how.
return propshould;
#socketPath
should exist.
return should;
should be a string.
return propshouldbe;
should equal are.
return propshould;
#port
should exist.
return should;
should be a string.
return propshouldbe;
should equal you.
return propshould;
#agent
should exist.
return should;
should be a string.
return propshouldbe;
should equal ?.
return propshould;
#method
should exist.
return should;
should be a string.
return propshouldbe;
should equal i.
return propshould;
#path
should exist.
return should;
should be a string.
return propshouldbe;
should equal am.
return propshould;
#localAddress
should exist.
return should;
should be a string.
return propshouldbe;
should equal local.address.
return propshould;
#auth
should exist.
return should;
should be a string.
return propshouldbe;
should equal username:pass.
return propshould;
#pro
should exist.
return should;
should be a string.
return propshouldbe;
should equal xy.
return propshould;
#fizz
should exist.
return should;
should be a string.
return propshouldbe;
should equal bang.
return propshould;
#overwritten
should exist.
return should;
should be a boolean.
return propshouldbe;
should equal true.
return propshould;
when using ignorePath
should ignore the path of the req.url
passed in but use the target path.
var outgoing = {};var myEndpoint = 'https://whatever.com/some/crazy/path/whoooo';common;0 _chaiexpectoutgoingpathto;
and prependPath: false, it should ignore path of target and incoming request.
var outgoing = {};var myEndpoint = 'https://whatever.com/some/crazy/path/whoooo';common;0 _chaiexpectoutgoingpathto;
when using changeOrigin
should correctly set the port to the host when it is a non-standard port using url.parse.
var outgoing = {};var myEndpoint = 'https://myCouch.com:6984';common;0 _chaiexpectoutgoingheadershostto;
should correctly set the port to the host when it is a non-standard port when setting host and port manually (which ignores port).
var outgoing = {};common;0 _chaiexpectoutgoingheadershostto;
should not pass null as last arg to #urlJoin
should exist.
return should;
should have path.
return outgoingshouldbethathasthatis;
should be empty.
return outgoingpathshould;
#setupSocket
should setup a socket
should still have socketConfig.
return should;
should have timeout.
return socketConfigshouldbethathasthatis;
should have nodelay.
return socketConfigshouldbethathasthatis;
should have keepalive.
return socketConfigshouldbethathasthatis;
should have correct timeout value.
return socketConfigtimeoutshould;
should have correct nodelay value.
return socketConfignodelayshould;
should have correct keepalive value.
return socketConfigkeepaliveshould;
lib/es-http-proxy/passes/web.js
#deleteLength
should change content-length
for DELETE requests.
var stubRequest = method: 'DELETE' headers: {};webPasses;0 _chaiexpectstubRequestheaders'content-length'to;
should change content-length
for OPTIONS requests.
var stubRequest = method: 'OPTIONS' headers: {};webPasses;0 _chaiexpectstubRequestheaders'content-length'to;
should remove transfer-encoding
from empty DELETE requests.
var stubRequest = method: 'DELETE' headers: 'transfer-encoding': 'chunked' ;webPasses;0 _chaiexpectstubRequestheaders'content-length'to;0 _chaiexpectstubRequestheaderstonothave;
#timeout
should set timeout on the socket.
var done = false stubRequest = socket: { done = value; } ;webPasses;0 _chaiexpectdoneto;
#XHeaders
set the correct x-forwarded-* headers.
webPasses;0 _chaiexpectstubRequestheaders'x-forwarded-for'to;0 _chaiexpectstubRequestheaders'x-forwarded-port'to;0 _chaiexpectstubRequestheaders'x-forwarded-proto'to;
#createProxyServer.web() using own http server
lib/es-http-proxy/passes/web-outgoing.js
#setRedirectHostRewrite
rewrites location host with hostRewrite
on 301.
thisproxyResstatusCode = code;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
on 302.
thisproxyResstatusCode = code;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
on 307.
thisproxyResstatusCode = code;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
on 308.
thisproxyResstatusCode = code;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
not on 200.
thisproxyResstatusCode = 200;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
not when hostRewrite is unset.
delete thisoptionshostRewrite;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
takes precedence over autoRewrite.
thisoptionsautoRewrite = true;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
not when the redirected location does not match target host.
thisproxyResstatusCode = 302;thisproxyResheaderslocation = 'http://some-other/';httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
not when the redirected location does not match target port.
thisproxyResstatusCode = 302;thisproxyResheaderslocation = 'http://backend.com:8080/';httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
rewrites location host with autoRewrite
on 301.
thisproxyResstatusCode = code;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
on 302.
thisproxyResstatusCode = code;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
on 307.
thisproxyResstatusCode = code;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
on 308.
thisproxyResstatusCode = code;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
not on 200.
thisproxyResstatusCode = 200;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
not when autoRewrite is unset.
delete thisoptionsautoRewrite;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
not when the redirected location does not match target host.
thisproxyResstatusCode = 302;thisproxyResheaderslocation = 'http://some-other/';httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
not when the redirected location does not match target port.
thisproxyResstatusCode = 302;thisproxyResheaderslocation = 'http://backend.com:8080/';httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
rewrites location protocol with protocolRewrite
on 301.
thisproxyResstatusCode = code;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
on 302.
thisproxyResstatusCode = code;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
on 307.
thisproxyResstatusCode = code;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
on 308.
thisproxyResstatusCode = code;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
not on 200.
thisproxyResstatusCode = 200;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
not when protocolRewrite is unset.
delete thisoptionsprotocolRewrite;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
works together with hostRewrite.
thisoptionshostRewrite = 'ext-manual.com';httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
works together with autoRewrite.
thisoptionsautoRewrite = true;httpProxy;0 _chaiexpectthisproxyResheaderslocationto;
#setConnection
set the right connection with 1.0 - close
.
var proxyRes = headers: {} ;httpProxy;0 _chaiexpectproxyResheadersconnectionto;
set the right connection with 1.0 - req.connection.
var proxyRes = headers: {} ;httpProxy;0 _chaiexpectproxyResheadersconnectionto;
set the right connection - req.connection.
var proxyRes = headers: {} ;httpProxy;0 _chaiexpectproxyResheadersconnectionto;
set the right connection - keep-alive
.
var proxyRes = headers: {} ;httpProxy;0 _chaiexpectproxyResheadersconnectionto;
#writeStatusCode
should write status code.
var res = { 0 _chaiexpectnto; } ;httpProxy;
lib/es-http-proxy/passes/ws-incoming.js
#checkMethodAndHeader
should drop non-GET connections.
var destroyCalled = false stubRequest = method: 'DELETE' headers: {} stubSocket = { // Simulate Socket.destroy() method when call destroyCalled = true; } ;var returnValue = httpProxy;0 _chaiexpectreturnValueto;0 _chaiexpectdestroyCalledto;
should drop connections when no upgrade header.
var destroyCalled = false stubRequest = method: 'GET' headers: {} stubSocket = { // Simulate Socket.destroy() method when call destroyCalled = true; } ;var returnValue = httpProxy;0 _chaiexpectreturnValueto;0 _chaiexpectdestroyCalledto;
should drop connections when upgrade header is different of websocket
.
var destroyCalled = false stubRequest = method: 'GET' headers: upgrade: 'anotherprotocol' stubSocket = { // Simulate Socket.destroy() method when call destroyCalled = true; } ;var returnValue = httpProxy;0 _chaiexpectreturnValueto;0 _chaiexpectdestroyCalledto;
should return nothing when all is ok.
var destroyCalled = false stubRequest = method: 'GET' headers: upgrade: 'websocket' stubSocket = { // Simulate Socket.destroy() method when call destroyCalled = true; } ;var returnValue = httpProxy;0 _chaiexpectreturnValueto;0 _chaiexpectdestroyCalledto;
#XHeaders
return if no forward request.
var returnValue = httpProxy;0 _chaiexpectreturnValuetobeundefined;
set the correct x-forwarded-* headers from req.connection.
var stubRequest = connection: remoteAddress: '192.168.1.2' remotePort: '8080' headers: host: '192.168.1.2:8080' ;httpProxy;0 _chaiexpectstubRequestheaders'x-forwarded-for'to;0 _chaiexpectstubRequestheaders'x-forwarded-port'to;0 _chaiexpectstubRequestheaders'x-forwarded-proto'to;
set the correct x-forwarded-* headers from req.socket.
var stubRequest = socket: remoteAddress: '192.168.1.3' remotePort: '8181' connection: pair: true headers: host: '192.168.1.3:8181' ;httpProxy;0 _chaiexpectstubRequestheaders'x-forwarded-for'to;0 _chaiexpectstubRequestheaders'x-forwarded-port'to;0 _chaiexpectstubRequestheaders'x-forwarded-proto'to;
ProxyServer
should exist.
return should;
should be a function.
return _ProxyServer2defaultshouldbe;
should create instanceof EE3.
return shouldbe;
lib/es-http-proxy.js
#createProxyServer
should return an object otherwise
should exist.
return should;
should be an object.
return objshouldbe;
should have web function.
return objshouldhavethatis;
should have ws function.
return objshouldhavethatis;
should have listen function.
return objshouldhavethatis;
#createProxyServer with forward options and using web-incoming passes
should pipe the request using web-incoming#stream method.
var ports = source: genport proxy: genport ;var proxy = 0 _esHttpProxycreateProxyServer forward: 'http://127.0.0.1:' + portssource;var source = _http2default;source;_http2default;
#createProxyServer using the web-incoming passes
should proxy sse.
var ports = source: genport proxy: genport proxy = 0 _esHttpProxycreateProxyServer target: 'http://localhost:' + portssource proxyServer = proxy source = _http2default sse = source path: '/' ;sse;source;var options = hostname: 'localhost' port: portsproxy ;var req = _http2default;
should make the request on pipe and finish it.
var ports = source: genport proxy: genport ;var proxy = 0 _esHttpProxycreateProxyServer target: 'http://127.0.0.1:' + portssource;var source = _http2default;source;_http2default;
#createProxyServer using the web-incoming passes
should make the request, handle response and finish it.
var ports = source: genport proxy: genport ;var proxy = 0 _esHttpProxycreateProxyServer target: 'http://127.0.0.1:' + portssource;var source = _http2default;source;_http2default;
#createProxyServer() method with error response
should make the request and emit the error event.
var ports = source: genport proxy: genport ;var proxy = 0 _esHttpProxycreateProxyServer target: 'http://127.0.0.1:' + portssource;proxy;proxy;_http2default;
#createProxyServer setting the correct timeout value
should hang up the socket at the timeout.
this;var ports = source: genport proxy: genport ;var proxy = 0 _esHttpProxycreateProxyServer target: 'http://127.0.0.1:' + portssource timeout: 3;proxy;var source = _http2default;source;var testReq = _http2default;testReq;testReq;
#createProxyServer using the ws-incoming passes
should proxy the websockets stream.
var ports = source: genport proxy: genport ;var proxy = 0 _esHttpProxycreateProxyServer target: 'ws://127.0.0.1:' + portssource ws: true;var proxyServer = proxy;var destiny = port: portssource { var client = 'ws://127.0.0.1:' + portsproxy; client; client;};destiny;
should emit error on proxy error.
var ports = source: genport proxy: genport ;var proxy = 0 _esHttpProxycreateProxyServer target: 'ws://127.0.0.1:' + portssource ws: true;var proxyServer = proxy;var client = 'ws://127.0.0.1:' + portsproxy;client;var count = 0; { count += 1; if count === 2 ;}client;proxy;
should close client socket if upstream is closed before upgrade.
var ports = source: genport proxy: genport ;var server = _http2default;server;server;var proxy = 0 _esHttpProxycreateProxyServer target: 'ws://127.0.0.1:' + portssource ws: true;var proxyServer = proxy;var client = 'ws://127.0.0.1:' + portsproxy;client;client;
should proxy a socket.io stream.
var ports = source: genport proxy: genport ;var proxy = 0 _esHttpProxycreateProxyServer target: 'ws://127.0.0.1:' + portssource ws: true;var proxyServer = proxy;var server = _http2default;var destiny = _socket2default; { var client = _socket4default; client; client;}server;server;destinysockets;
should emit open and close events when socket.io client connects and disconnects.
var ports = source: genport proxy: genport ;var proxy = 0 _esHttpProxycreateProxyServer target: 'ws://127.0.0.1:' + portssource ws: true;var proxyServer = proxy;var server = _http2default;var destiny = _socket2default; { var client = _socket4default; client;}var count = 0;proxyServer;proxyServer;server;server;
should pass all set-cookie headers to client.
var ports = source: genport proxy: genport ;var proxy = 0 _esHttpProxycreateProxyServer target: 'ws://127.0.0.1:' + portssource ws: true proxyServer = proxy destiny = port: portssource { var key = Math; var requestOptions = port: portsproxy host: '127.0.0.1' headers: 'Connection': 'Upgrade' 'Upgrade': 'websocket' 'Host': 'ws://127.0.0.1' 'Sec-WebSocket-Version': 13 'Sec-WebSocket-Key': key ; var req = _http2default; req; req;};destiny;
should detect a proxyReq event and modify headers.
var ports = source: genport proxy: genport proxy proxyServer destiny;proxy = 0 _esHttpProxycreateProxyServer target: 'ws://127.0.0.1:' + portssource ws: true;proxy;proxyServer = proxy;destiny = port: portssource { var client = 'ws://127.0.0.1:' + portsproxy; client; client;};destiny;
should forward frames with single frame payload (including on node 4.x).
var payload = Array65529;var ports = source: genport proxy: genport ;var proxy = 0 _esHttpProxycreateProxyServer target: 'ws://127.0.0.1:' + portssource ws: true proxyServer = proxy destiny = port: portssource { var client = 'ws://127.0.0.1:' + portsproxy; client; client;};destiny;
should forward continuation frames with big payload (including on node 4.x).
var payload = Array65530;var ports = source: genport proxy: genport ;var proxy = 0 _esHttpProxycreateProxyServer target: 'ws://127.0.0.1:' + portssource ws: true proxyServer = proxy destiny = port: portssource { var client = 'ws://127.0.0.1:' + portsproxy; client; client;};destiny;
lib/es-http-proxy.js
HTTPS #createProxyServer
HTTPS to HTTP
should proxy the request en send back the response.
var ports = source: genport proxy: genport ;var source = _http2default;source;var proxy = 0 _esHttpProxycreateProxyServer target: 'http://127.0.0.1:' + portssource ssl: key: _fs2default cert: _fs2default ciphers: 'AES128-GCM-SHA256' ;_https2default;
HTTP to HTTPS
should proxy the request and send back the response.
var ports = source: genport proxy: genport ;var source = _https2default;source;var proxy = 0 _esHttpProxycreateProxyServer target: 'https://127.0.0.1:' + portssource // Allow to use SSL self signed secure: false;_http2default;
HTTPS to HTTPS
should proxy the request en send back the response.
var ports = source: genport proxy: genport ;var source = _https2default;source;var proxy = 0 _esHttpProxycreateProxyServer target: 'https://127.0.0.1:' + portssource ssl: key: _fs2default cert: _fs2default ciphers: 'AES128-GCM-SHA256' secure: false;_https2default;
HTTPS not allow SSL self signed
should fail with error.
var ports = source: genport proxy: genport ;var source = _https2default;var proxy = 0 _esHttpProxycreateProxyServer target: 'https://127.0.0.1:' + portssource secure: true;proxy;proxy;_http2default;
HTTPS to HTTP using own server
should proxy the request en send back the response.
var ports = source: genport proxy: genport ;var source = _http2default;source;var proxy = 0 _esHttpProxycreateProxyServer agent: maxSockets: 2 ;var ownServer = _https2default;_https2default;