

 \hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12012}{}\doxysection{node-\/http-\/proxy $<$a href=\char`\"{}https\+://travis-\/ci.\+org/http-\/party/node-\/http-\/proxy\char`\"{}$>$$<$img src=\char`\"{}https\+://travis-\/ci.\+org/http-\/party/node-\/http-\/proxy.\+svg?branch=master\char`\"{} alt=\char`\"{}\+Build Status\char`\"{}/$>$$<$/a$>$ $<$a href=\char`\"{}https\+://codecov.\+io/gh/http-\/party/node-\/http-\/proxy\char`\"{}$>$$<$img src=\char`\"{}https\+://codecov.\+io/gh/http-\/party/node-\/http-\/proxy/branch/master/graph/badge.\+svg\char`\"{} alt=\char`\"{}codecov\char`\"{}/$>$$<$/a$>$}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12012}
{\ttfamily node-\/http-\/proxy} is an HTTP programmable proxying library that supports websockets. It is suitable for implementing components such as reverse proxies and load balancers.\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12013}{}\doxysubsubsection{Table of Contents}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12013}

\begin{DoxyItemize}
\item \href{\#installation}{\texttt{ Installation}}
\item \href{\#upgrading-from-08x-}{\texttt{ Upgrading from 0.\+8.\+x ?}}
\item \href{\#core-concept}{\texttt{ Core Concept}}
\item \href{\#use-cases}{\texttt{ Use Cases}}
\begin{DoxyItemize}
\item \href{\#setup-a-basic-stand-alone-proxy-server}{\texttt{ Setup a basic stand-\/alone proxy server}}
\item \href{\#setup-a-stand-alone-proxy-server-with-custom-server-logic}{\texttt{ Setup a stand-\/alone proxy server with custom server logic}}
\item \href{\#setup-a-stand-alone-proxy-server-with-proxy-request-header-re-writing}{\texttt{ Setup a stand-\/alone proxy server with proxy request header re-\/writing}}
\item \href{\#modify-a-response-from-a-proxied-server}{\texttt{ Modify a response from a proxied server}}
\item \href{\#setup-a-stand-alone-proxy-server-with-latency}{\texttt{ Setup a stand-\/alone proxy server with latency}}
\item \href{\#using-https}{\texttt{ Using HTTPS}}
\item \href{\#proxying-websockets}{\texttt{ Proxying Web\+Sockets}}
\end{DoxyItemize}
\item \href{\#options}{\texttt{ Options}}
\item \href{\#listening-for-proxy-events}{\texttt{ Listening for proxy events}}
\item \href{\#shutdown}{\texttt{ Shutdown}}
\item \href{\#miscellaneous}{\texttt{ Miscellaneous}}
\begin{DoxyItemize}
\item \href{\#test}{\texttt{ Test}}
\item \href{\#proxytable-api}{\texttt{ Proxy\+Table API}}
\item \href{\#logo}{\texttt{ Logo}}
\end{DoxyItemize}
\item \href{\#contributing-and-issues}{\texttt{ Contributing and Issues}}
\item \href{\#license}{\texttt{ License}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12014}{}\doxysubsubsection{Installation}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12014}
{\ttfamily npm install http-\/proxy -\/-\/save}

{\bfseries{\href{\#table-of-contents}{\texttt{ Back to top}}}}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12015}{}\doxysubsubsection{Upgrading from 0.\+8.\+x ?}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12015}
Click here

{\bfseries{\href{\#table-of-contents}{\texttt{ Back to top}}}}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12016}{}\doxysubsubsection{Core Concept}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12016}
A new proxy is created by calling {\ttfamily create\+Proxy\+Server} and passing an {\ttfamily options} object as argument (\href{lib/http-proxy.js\#L26-L42}{\texttt{ valid properties are available here}})


\begin{DoxyCode}{0}
\DoxyCodeLine{var httpProxy = require('http-\/proxy');}
\DoxyCodeLine{}
\DoxyCodeLine{var proxy = httpProxy.createProxyServer(options); // See (†) }

\end{DoxyCode}
 †\+Unless listen(..) is invoked on the object, this does not create a webserver. See below.

An object will be returned with four methods\+:


\begin{DoxyItemize}
\item web {\ttfamily req, res, \mbox{[}options\mbox{]}} (used for proxying regular HTTP(\+S) requests)
\item ws {\ttfamily req, socket, head, \mbox{[}options\mbox{]}} (used for proxying WS(\+S) requests)
\item listen {\ttfamily port} (a function that wraps the object in a webserver, for your convenience)
\item close {\ttfamily \mbox{[}callback\mbox{]}} (a function that closes the inner webserver and stops listening on given port)
\end{DoxyItemize}

It is then possible to proxy requests by calling these functions


\begin{DoxyCode}{0}
\DoxyCodeLine{http.createServer(function(req, res) \{}
\DoxyCodeLine{  proxy.web(req, res, \{ target: 'http://mytarget.com:8080' \});}
\DoxyCodeLine{\}); }

\end{DoxyCode}


Errors can be listened on either using the Event Emitter API


\begin{DoxyCode}{0}
\DoxyCodeLine{proxy.on('error', function(e) \{}
\DoxyCodeLine{  ...}
\DoxyCodeLine{\}); }

\end{DoxyCode}


or using the callback API


\begin{DoxyCode}{0}
\DoxyCodeLine{proxy.web(req, res, \{ target: 'http://mytarget.com:8080' \}, function(e) \{ ... \}); }

\end{DoxyCode}


When a request is proxied it follows two different pipelines (\href{lib/http-proxy/passes}{\texttt{ available here}}) which apply transformations to both the {\ttfamily req} and {\ttfamily res} object. The first pipeline (incoming) 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.

{\bfseries{\href{\#table-of-contents}{\texttt{ Back to top}}}}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12017}{}\doxysubsubsection{Use Cases}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12017}
\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12018}{}\doxyparagraph{Setup a basic stand-\/alone proxy server}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12018}

\begin{DoxyCode}{0}
\DoxyCodeLine{var http = require('http'),}
\DoxyCodeLine{    httpProxy = require('http-\/proxy');}
\DoxyCodeLine{//}
\DoxyCodeLine{// Create your proxy server and set the target in the options.}
\DoxyCodeLine{//}
\DoxyCodeLine{httpProxy.createProxyServer(\{target:'http://localhost:9000'\}).listen(8000); // See (†)}
\DoxyCodeLine{}
\DoxyCodeLine{//}
\DoxyCodeLine{// Create your target server}
\DoxyCodeLine{//}
\DoxyCodeLine{http.createServer(function (req, res) \{}
\DoxyCodeLine{  res.writeHead(200, \{ 'Content-\/Type': 'text/plain' \});}
\DoxyCodeLine{  res.write('request successfully proxied!' + '\(\backslash\)n' + JSON.stringify(req.headers, true, 2));}
\DoxyCodeLine{  res.end();}
\DoxyCodeLine{\}).listen(9000); }

\end{DoxyCode}
 †\+Invoking listen(..) triggers the creation of a web server. Otherwise, just the proxy instance is created.

{\bfseries{\href{\#table-of-contents}{\texttt{ Back to top}}}}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12019}{}\doxyparagraph{Setup a stand-\/alone proxy server with custom server logic}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12019}
This example shows how you can proxy a request using your own HTTP server and also you can put your own logic to handle the request.


\begin{DoxyCode}{0}
\DoxyCodeLine{var http = require('http'),}
\DoxyCodeLine{    httpProxy = require('http-\/proxy');}
\DoxyCodeLine{}
\DoxyCodeLine{//}
\DoxyCodeLine{// Create a proxy server with custom application logic}
\DoxyCodeLine{//}
\DoxyCodeLine{var proxy = httpProxy.createProxyServer(\{\});}
\DoxyCodeLine{}
\DoxyCodeLine{//}
\DoxyCodeLine{// Create your custom server and just call `proxy.web()` to proxy}
\DoxyCodeLine{// a web request to the target passed in the options}
\DoxyCodeLine{// also you can use `proxy.ws()` to proxy a websockets request}
\DoxyCodeLine{//}
\DoxyCodeLine{var server = http.createServer(function(req, res) \{}
\DoxyCodeLine{  // You can define here your custom logic to handle the request}
\DoxyCodeLine{  // and then proxy the request.}
\DoxyCodeLine{  proxy.web(req, res, \{ target: 'http://127.0.0.1:5050' \});}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{console.log("{}listening on port 5050"{})}
\DoxyCodeLine{server.listen(5050); }

\end{DoxyCode}


{\bfseries{\href{\#table-of-contents}{\texttt{ Back to top}}}}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12020}{}\doxyparagraph{Setup a stand-\/alone proxy server with proxy request header re-\/writing}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12020}
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.


\begin{DoxyCode}{0}
\DoxyCodeLine{var http = require('http'),}
\DoxyCodeLine{    httpProxy = require('http-\/proxy');}
\DoxyCodeLine{}
\DoxyCodeLine{//}
\DoxyCodeLine{// Create a proxy server with custom application logic}
\DoxyCodeLine{//}
\DoxyCodeLine{var proxy = httpProxy.createProxyServer(\{\});}
\DoxyCodeLine{}
\DoxyCodeLine{// To modify the proxy connection before data is sent, you can listen}
\DoxyCodeLine{// for the 'proxyReq' event. When the event is fired, you will receive}
\DoxyCodeLine{// the following arguments:}
\DoxyCodeLine{// (http.ClientRequest proxyReq, http.IncomingMessage req,}
\DoxyCodeLine{//  http.ServerResponse res, Object options). This mechanism is useful when}
\DoxyCodeLine{// you need to modify the proxy request before the proxy connection}
\DoxyCodeLine{// is made to the target.}
\DoxyCodeLine{//}
\DoxyCodeLine{proxy.on('proxyReq', function(proxyReq, req, res, options) \{}
\DoxyCodeLine{  proxyReq.setHeader('X-\/Special-\/Proxy-\/Header', 'foobar');}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{var server = http.createServer(function(req, res) \{}
\DoxyCodeLine{  // You can define here your custom logic to handle the request}
\DoxyCodeLine{  // and then proxy the request.}
\DoxyCodeLine{  proxy.web(req, res, \{}
\DoxyCodeLine{    target: 'http://127.0.0.1:5050'}
\DoxyCodeLine{  \});}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{console.log("{}listening on port 5050"{})}
\DoxyCodeLine{server.listen(5050); }

\end{DoxyCode}


{\bfseries{\href{\#table-of-contents}{\texttt{ Back to top}}}}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12021}{}\doxyparagraph{Modify a response from a proxied server}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12021}
Sometimes when you have received a HTML/\+XML document from the server of origin you would like to modify it before forwarding it on.

\href{https://github.com/No9/harmon}{\texttt{ Harmon}} allows you to do this in a streaming style so as to keep the pressure on the proxy to a minimum.

{\bfseries{\href{\#table-of-contents}{\texttt{ Back to top}}}}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12022}{}\doxyparagraph{Setup a stand-\/alone proxy server with latency}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12022}

\begin{DoxyCode}{0}
\DoxyCodeLine{var http = require('http'),}
\DoxyCodeLine{    httpProxy = require('http-\/proxy');}
\DoxyCodeLine{}
\DoxyCodeLine{//}
\DoxyCodeLine{// Create a proxy server with latency}
\DoxyCodeLine{//}
\DoxyCodeLine{var proxy = httpProxy.createProxyServer();}
\DoxyCodeLine{}
\DoxyCodeLine{//}
\DoxyCodeLine{// Create your server that makes an operation that waits a while}
\DoxyCodeLine{// and then proxies the request}
\DoxyCodeLine{//}
\DoxyCodeLine{http.createServer(function (req, res) \{}
\DoxyCodeLine{  // This simulates an operation that takes 500ms to execute}
\DoxyCodeLine{  setTimeout(function () \{}
\DoxyCodeLine{    proxy.web(req, res, \{}
\DoxyCodeLine{      target: 'http://localhost:9008'}
\DoxyCodeLine{    \});}
\DoxyCodeLine{  \}, 500);}
\DoxyCodeLine{\}).listen(8008);}
\DoxyCodeLine{}
\DoxyCodeLine{//}
\DoxyCodeLine{// Create your target server}
\DoxyCodeLine{//}
\DoxyCodeLine{http.createServer(function (req, res) \{}
\DoxyCodeLine{  res.writeHead(200, \{ 'Content-\/Type': 'text/plain' \});}
\DoxyCodeLine{  res.write('request successfully proxied to: ' + req.url + '\(\backslash\)n' + JSON.stringify(req.headers, true, 2));}
\DoxyCodeLine{  res.end();}
\DoxyCodeLine{\}).listen(9008); }

\end{DoxyCode}


{\bfseries{\href{\#table-of-contents}{\texttt{ Back to top}}}}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12023}{}\doxyparagraph{Using HTTPS}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12023}
You can activate the validation of a secure SSL certificate to the target connection (avoid self-\/signed certs), just set {\ttfamily secure\+: true} in the options.

\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12024}%
\Hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12024}%
\doxysubparagraph*{HTTPS -\/$>$ HTTP}


\begin{DoxyCode}{0}
\DoxyCodeLine{//}
\DoxyCodeLine{// Create the HTTPS proxy server in front of a HTTP server}
\DoxyCodeLine{//}
\DoxyCodeLine{httpProxy.createServer(\{}
\DoxyCodeLine{  target: \{}
\DoxyCodeLine{    host: 'localhost',}
\DoxyCodeLine{    port: 9009}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  ssl: \{}
\DoxyCodeLine{    key: fs.readFileSync('valid-\/ssl-\/key.pem', 'utf8'),}
\DoxyCodeLine{    cert: fs.readFileSync('valid-\/ssl-\/cert.pem', 'utf8')}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}).listen(8009); }

\end{DoxyCode}


\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12025}%
\Hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12025}%
\doxysubparagraph*{HTTPS -\/$>$ HTTPS}


\begin{DoxyCode}{0}
\DoxyCodeLine{//}
\DoxyCodeLine{// Create the proxy server listening on port 443}
\DoxyCodeLine{//}
\DoxyCodeLine{httpProxy.createServer(\{}
\DoxyCodeLine{  ssl: \{}
\DoxyCodeLine{    key: fs.readFileSync('valid-\/ssl-\/key.pem', 'utf8'),}
\DoxyCodeLine{    cert: fs.readFileSync('valid-\/ssl-\/cert.pem', 'utf8')}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  target: 'https://localhost:9010',}
\DoxyCodeLine{  secure: true // Depends on your needs, could be false.}
\DoxyCodeLine{\}).listen(443); }

\end{DoxyCode}


\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12026}%
\Hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12026}%
\doxysubparagraph*{HTTP -\/$>$ HTTPS (using a PKCS12 client certificate)}


\begin{DoxyCode}{0}
\DoxyCodeLine{//}
\DoxyCodeLine{// Create an HTTP proxy server with an HTTPS target}
\DoxyCodeLine{//}
\DoxyCodeLine{httpProxy.createProxyServer(\{}
\DoxyCodeLine{  target: \{}
\DoxyCodeLine{    protocol: 'https:',}
\DoxyCodeLine{    host: 'my-\/domain-\/name',}
\DoxyCodeLine{    port: 443,}
\DoxyCodeLine{    pfx: fs.readFileSync('path/to/certificate.p12'),}
\DoxyCodeLine{    passphrase: 'password',}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  changeOrigin: true,}
\DoxyCodeLine{\}).listen(8000); }

\end{DoxyCode}


{\bfseries{\href{\#table-of-contents}{\texttt{ Back to top}}}}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12027}{}\doxyparagraph{Proxying Web\+Sockets}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12027}
You can activate the websocket support for the proxy using {\ttfamily ws\+:true} in the options.


\begin{DoxyCode}{0}
\DoxyCodeLine{//}
\DoxyCodeLine{// Create a proxy server for websockets}
\DoxyCodeLine{//}
\DoxyCodeLine{httpProxy.createServer(\{}
\DoxyCodeLine{  target: 'ws://localhost:9014',}
\DoxyCodeLine{  ws: true}
\DoxyCodeLine{\}).listen(8014); }

\end{DoxyCode}


Also you can proxy the websocket requests just calling the {\ttfamily ws(req, socket, head)} method.


\begin{DoxyCode}{0}
\DoxyCodeLine{//}
\DoxyCodeLine{// Setup our server to proxy standard HTTP requests}
\DoxyCodeLine{//}
\DoxyCodeLine{var proxy = new httpProxy.createProxyServer(\{}
\DoxyCodeLine{  target: \{}
\DoxyCodeLine{    host: 'localhost',}
\DoxyCodeLine{    port: 9015}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\});}
\DoxyCodeLine{var proxyServer = http.createServer(function (req, res) \{}
\DoxyCodeLine{  proxy.web(req, res);}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{//}
\DoxyCodeLine{// Listen to the `upgrade` event and proxy the}
\DoxyCodeLine{// WebSocket requests as well.}
\DoxyCodeLine{//}
\DoxyCodeLine{proxyServer.on('upgrade', function (req, socket, head) \{}
\DoxyCodeLine{  proxy.ws(req, socket, head);}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{proxyServer.listen(8015); }

\end{DoxyCode}


{\bfseries{\href{\#table-of-contents}{\texttt{ Back to top}}}}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12028}{}\doxysubsubsection{Options}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12028}
{\ttfamily http\+Proxy.\+create\+Proxy\+Server} supports the following options\+:


\begin{DoxyItemize}
\item {\bfseries{target}}\+: url string to be parsed with the url module
\item {\bfseries{forward}}\+: url string to be parsed with the url module
\item {\bfseries{agent}}\+: object to be passed to http(s).request (see Node\textquotesingle{}s \href{http://nodejs.org/api/https.html\#https_class_https_agent}{\texttt{ https agent}} and \href{http://nodejs.org/api/http.html\#http_class_http_agent}{\texttt{ http agent}} objects)
\item {\bfseries{ssl}}\+: object to be passed to https.\+create\+Server()
\item {\bfseries{ws}}\+: true/false, if you want to proxy websockets
\item {\bfseries{xfwd}}\+: true/false, adds x-\/forward headers
\item {\bfseries{secure}}\+: true/false, if you want to verify the SSL Certs
\item {\bfseries{to\+Proxy}}\+: true/false, passes the absolute URL as the {\ttfamily path} (useful for proxying to proxies)
\item {\bfseries{prepend\+Path}}\+: true/false, Default\+: true -\/ specify whether you want to prepend the target\textquotesingle{}s path to the proxy path
\item {\bfseries{ignore\+Path}}\+: 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).
\item {\bfseries{local\+Address}}\+: Local interface string to bind for outgoing connections
\item {\bfseries{change\+Origin}}\+: true/false, Default\+: false -\/ changes the origin of the host header to the target URL
\item {\bfseries{preserve\+Header\+Key\+Case}}\+: true/false, Default\+: false -\/ specify whether you want to keep letter case of response header key
\item {\bfseries{auth}}\+: Basic authentication i.\+e. \textquotesingle{}user\+:password\textquotesingle{} to compute an Authorization header.
\item {\bfseries{host\+Rewrite}}\+: rewrites the location hostname on (201/301/302/307/308) redirects.
\item {\bfseries{auto\+Rewrite}}\+: rewrites the location host/port on (201/301/302/307/308) redirects based on requested host/port. Default\+: false.
\item {\bfseries{protocol\+Rewrite}}\+: rewrites the location protocol on (201/301/302/307/308) redirects to \textquotesingle{}http\textquotesingle{} or \textquotesingle{}https\textquotesingle{}. Default\+: null.
\item {\bfseries{cookie\+Domain\+Rewrite}}\+: rewrites domain of {\ttfamily set-\/cookie} headers. Possible values\+:
\begin{DoxyItemize}
\item {\ttfamily false} (default)\+: disable cookie rewriting
\item String\+: new domain, for example {\ttfamily cookie\+Domain\+Rewrite\+: \char`\"{}new.\+domain\char`\"{}}. To remove the domain, use {\ttfamily cookie\+Domain\+Rewrite\+: \char`\"{}\char`\"{}}.
\item Object\+: mapping of domains to new domains, use {\ttfamily \char`\"{}$\ast$\char`\"{}} to match all domains. For example keep one domain unchanged, rewrite one domain and remove other domains\+: \`{}\`{}\`{} cookie\+Domain\+Rewrite\+: \{ \char`\"{}unchanged.\+domain\char`\"{}\+: \char`\"{}unchanged.\+domain\char`\"{}, \char`\"{}old.\+domain\char`\"{}\+: \char`\"{}new.\+domain\char`\"{}, \char`\"{}$\ast$\char`\"{}\+: \char`\"{}\char`\"{} \} \`{}\`{}{\ttfamily }
\end{DoxyItemize}
\item {\ttfamily  $\ast$$\ast$cookie\+Path\+Rewrite$\ast$$\ast$\+: rewrites path of}set-\/cookie{\ttfamily headers. Possible values\+: $\ast$}false$<$tt$>$(default)\+: disable cookie rewriting
\begin{DoxyItemize}
\item String\+: new path, for examplecookie\+Path\+Rewrite\+: \char`\"{}/new\+Path/\char`\"{}{\ttfamily . To remove the path, use}cookie\+Path\+Rewrite\+: \char`\"{}\char`\"{}{\ttfamily . To set path to root use}cookie\+Path\+Rewrite\+: \char`\"{}/\char`\"{}{\ttfamily .}
\item {\ttfamily Object\+: mapping of paths to new paths, use}\char`\"{}$\ast$\char`\"{}\`{} to match all paths. For example, to keep one path unchanged, rewrite one path and remove other paths\+: \`{}\`{}\`{} cookie\+Path\+Rewrite\+: \{ \char`\"{}/unchanged.\+path/\char`\"{}\+: \char`\"{}/unchanged.\+path/\char`\"{}, \char`\"{}/old.\+path/\char`\"{}\+: \char`\"{}/new.\+path/\char`\"{}, \char`\"{}$\ast$\char`\"{}\+: \char`\"{}\char`\"{} \} \`{}\`{}\`{}
\end{DoxyItemize}
\item {\bfseries{headers}}\+: object with extra headers to be added to target requests.
\item {\bfseries{proxy\+Timeout}}\+: timeout (in millis) for outgoing proxy requests
\item {\bfseries{timeout}}\+: timeout (in millis) for incoming requests
\item {\bfseries{follow\+Redirects}}\+: true/false, Default\+: false -\/ specify whether you want to follow redirects
\item {\bfseries{self\+Handle\+Response}} true/false, if set to true, none of the web\+Outgoing passes are called and it\textquotesingle{}s your responsibility to appropriately return the response by listening and acting on the {\ttfamily proxy\+Res} event
\item {\bfseries{buffer}}\+: stream of data to send as the request body. Maybe you have some middleware that consumes the request stream before proxying it on e.\+g. If you read the body of a request into a field called \textquotesingle{}req.\+rawbody\textquotesingle{} you could restream this field in the buffer option\+:

\`{}\`{}` \textquotesingle{}use strict';

const streamify = require(\textquotesingle{}stream-\/array\textquotesingle{}); const Http\+Proxy = require(\textquotesingle{}http-\/proxy\textquotesingle{}); const proxy = new Http\+Proxy();

module.\+exports = (req, res, next) =$>$ \{

proxy.\+web(req, res, \{ target\+: \textquotesingle{}\href{http://localhost:4003/'}{\texttt{ http\+://localhost\+:4003/\textquotesingle{}}}, buffer\+: streamify(req.\+raw\+Body) \}, next);

\}; \`{}\`{}\`{}
\end{DoxyItemize}

{\bfseries{NOTE\+:}} {\ttfamily options.\+ws} and {\ttfamily options.\+ssl} are optional. {\ttfamily options.\+target} and {\ttfamily options.\+forward} cannot both be missing

If you are using the {\ttfamily proxy\+Server.\+listen} method, the following options are also applicable\+:


\begin{DoxyItemize}
\item {\bfseries{ssl}}\+: object to be passed to https.\+create\+Server()
\item {\bfseries{ws}}\+: true/false, if you want to proxy websockets
\end{DoxyItemize}

{\bfseries{\href{\#table-of-contents}{\texttt{ Back to top}}}}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12029}{}\doxysubsubsection{Listening for proxy events}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12029}

\begin{DoxyItemize}
\item {\ttfamily error}\+: The error event is emitted if the request to the target fail. {\bfseries{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.}}
\item {\ttfamily proxy\+Req}\+: This event is emitted before the data is sent. It gives you a chance to alter the proxy\+Req request object. Applies to \char`\"{}web\char`\"{} connections
\item {\ttfamily proxy\+Req\+Ws}\+: This event is emitted before the data is sent. It gives you a chance to alter the proxy\+Req request object. Applies to \char`\"{}websocket\char`\"{} connections
\item {\ttfamily proxy\+Res}\+: This event is emitted if the request to the target got a response.
\item {\ttfamily open}\+: This event is emitted once the proxy websocket was created and piped into the target websocket.
\item {\ttfamily close}\+: This event is emitted once the proxy websocket was closed.
\item (DEPRECATED) {\ttfamily proxy\+Socket}\+: Deprecated in favor of {\ttfamily open}.
\end{DoxyItemize}


\begin{DoxyCode}{0}
\DoxyCodeLine{var httpProxy = require('http-\/proxy');}
\DoxyCodeLine{// Error example}
\DoxyCodeLine{//}
\DoxyCodeLine{// Http Proxy Server with bad target}
\DoxyCodeLine{//}
\DoxyCodeLine{var proxy = httpProxy.createServer(\{}
\DoxyCodeLine{  target:'http://localhost:9005'}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{proxy.listen(8005);}
\DoxyCodeLine{}
\DoxyCodeLine{//}
\DoxyCodeLine{// Listen for the `error` event on `proxy`.}
\DoxyCodeLine{proxy.on('error', function (err, req, res) \{}
\DoxyCodeLine{  res.writeHead(500, \{}
\DoxyCodeLine{    'Content-\/Type': 'text/plain'}
\DoxyCodeLine{  \});}
\DoxyCodeLine{}
\DoxyCodeLine{  res.end('Something went wrong. And we are reporting a custom error message.');}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{//}
\DoxyCodeLine{// Listen for the `proxyRes` event on `proxy`.}
\DoxyCodeLine{//}
\DoxyCodeLine{proxy.on('proxyRes', function (proxyRes, req, res) \{}
\DoxyCodeLine{  console.log('RAW Response from the target', JSON.stringify(proxyRes.headers, true, 2));}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{//}
\DoxyCodeLine{// Listen for the `open` event on `proxy`.}
\DoxyCodeLine{//}
\DoxyCodeLine{proxy.on('open', function (proxySocket) \{}
\DoxyCodeLine{  // listen for messages coming FROM the target here}
\DoxyCodeLine{  proxySocket.on('data', hybiParseAndLogMessage);}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{//}
\DoxyCodeLine{// Listen for the `close` event on `proxy`.}
\DoxyCodeLine{//}
\DoxyCodeLine{proxy.on('close', function (res, socket, head) \{}
\DoxyCodeLine{  // view disconnected websocket connections}
\DoxyCodeLine{  console.log('Client disconnected');}
\DoxyCodeLine{\}); }

\end{DoxyCode}


{\bfseries{\href{\#table-of-contents}{\texttt{ Back to top}}}}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12030}{}\doxysubsubsection{Shutdown}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12030}

\begin{DoxyItemize}
\item When testing or running server within another program it may be necessary to close the proxy.
\item This will stop the proxy from accepting new connections.
\end{DoxyItemize}


\begin{DoxyCode}{0}
\DoxyCodeLine{var proxy = new httpProxy.createProxyServer(\{}
\DoxyCodeLine{  target: \{}
\DoxyCodeLine{    host: 'localhost',}
\DoxyCodeLine{    port: 1337}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{proxy.close(); }

\end{DoxyCode}


{\bfseries{\href{\#table-of-contents}{\texttt{ Back to top}}}}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12031}{}\doxysubsubsection{Miscellaneous}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12031}
If you want to handle your own response after receiving the {\ttfamily proxy\+Res}, you can do so with {\ttfamily self\+Handle\+Response}. As you can see below, if you use this option, you are able to intercept and read the {\ttfamily proxy\+Res} but you must also make sure to reply to the {\ttfamily res} itself otherwise the original client will never receive any data.\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12032}{}\doxysubsubsection{Modify response}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12032}

\begin{DoxyCode}{0}
\DoxyCodeLine{var option = \{}
\DoxyCodeLine{  target: target,}
\DoxyCodeLine{  selfHandleResponse : true}
\DoxyCodeLine{\};}
\DoxyCodeLine{proxy.on('proxyRes', function (proxyRes, req, res) \{}
\DoxyCodeLine{    var body = [];}
\DoxyCodeLine{    proxyRes.on('data', function (chunk) \{}
\DoxyCodeLine{        body.push(chunk);}
\DoxyCodeLine{    \});}
\DoxyCodeLine{    proxyRes.on('end', function () \{}
\DoxyCodeLine{        body = Buffer.concat(body).toString();}
\DoxyCodeLine{        console.log("{}res from proxied server:"{}, body);}
\DoxyCodeLine{        res.end("{}my response to cli"{});}
\DoxyCodeLine{    \});}
\DoxyCodeLine{\});}
\DoxyCodeLine{proxy.web(req, res, option);}

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12033}{}\doxyparagraph{Proxy\+Table API}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12033}
A proxy table API is available through this add-\/on \href{https://github.com/donasaur/http-proxy-rules}{\texttt{ module}}, which lets you define a set of rules to translate matching routes to target routes that the reverse proxy will talk to.\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12034}{}\doxyparagraph{Test}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12034}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm test }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12035}{}\doxyparagraph{Logo}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12035}
Logo created by \href{http://dribbble.com/diegopq}{\texttt{ Diego Pasquali}}

{\bfseries{\href{\#table-of-contents}{\texttt{ Back to top}}}}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12036}{}\doxysubsubsection{Contributing and Issues}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12036}

\begin{DoxyItemize}
\item Read carefully our \href{https://github.com/http-party/node-http-proxy/blob/master/CODE_OF_CONDUCT.md}{\texttt{ Code Of Conduct}}
\item Search on Google/\+Github
\item If you can\textquotesingle{}t find anything, open an issue
\item If you feel comfortable about fixing the issue, fork the repo
\item Commit to your local branch (which must be different from {\ttfamily master})
\item Submit your Pull Request (be sure to include tests and update documentation)
\end{DoxyItemize}

{\bfseries{\href{\#table-of-contents}{\texttt{ Back to top}}}}\hypertarget{md_sfcode_node_modules_http_proxy_README_autotoc_md12037}{}\doxysubsubsection{License}\label{md_sfcode_node_modules_http_proxy_README_autotoc_md12037}
$>$The MIT License (MIT) \begin{quote}
$>$Copyright (c) 2010 -\/ 2016 Charlie Robbins, Jarrett Cruger \& the Contributors.

$>$Permission is hereby granted, free of charge, to any person obtaining a copy $>$of this software and associated documentation files (the \char`\"{}\+Software\char`\"{}), to deal $>$in the Software without restriction, including without limitation the rights $>$to use, copy, modify, merge, publish, distribute, sublicense, and/or sell $>$copies of the Software, and to permit persons to whom the Software is $>$furnished to do so, subject to the following conditions\+:

$>$The above copyright notice and this permission notice shall be included in $>$all copies or substantial portions of the Software.

$>$THE SOFTWARE IS PROVIDED \char`\"{}\+AS IS\char`\"{}, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR $>$IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, $>$FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE $>$AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER $>$LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, $>$OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN $>$THE SOFTWARE. \end{quote}
