\hypertarget{md_sfcode_node_modules_socks_proxy_agent_README_autotoc_md28205}{}\doxysubsection{A SOCKS proxy $<$tt$>$http.\+Agent$<$/tt$>$ implementation for HTTP and HTTPS}\label{md_sfcode_node_modules_socks_proxy_agent_README_autotoc_md28205}
\href{https://travis-ci.org/TooTallNate/node-socks-proxy-agent}{\texttt{ }}

This module provides an {\ttfamily http.\+Agent} implementation that connects to a specified SOCKS proxy server, and can be used with the built-\/in {\ttfamily http} or {\ttfamily https} modules.

It can also be used in conjunction with the {\ttfamily ws} module to establish a Web\+Socket connection over a SOCKS proxy. See the \char`\"{}\+Examples\char`\"{} section below.\hypertarget{md_sfcode_node_modules_socks_proxy_agent_README_autotoc_md28206}{}\doxysection{Installation}\label{md_sfcode_node_modules_socks_proxy_agent_README_autotoc_md28206}
Install with {\ttfamily npm}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install socks-\/proxy-\/agent }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_socks_proxy_agent_README_autotoc_md28207}{}\doxysection{Examples}\label{md_sfcode_node_modules_socks_proxy_agent_README_autotoc_md28207}
\hypertarget{md_sfcode_node_modules_socks_proxy_agent_README_autotoc_md28208}{}\doxysubsubsection{$<$tt$>$http$<$/tt$>$ module example}\label{md_sfcode_node_modules_socks_proxy_agent_README_autotoc_md28208}

\begin{DoxyCode}{0}
\DoxyCodeLine{var url = require('url');}
\DoxyCodeLine{var http = require('http');}
\DoxyCodeLine{var SocksProxyAgent = require('socks-\/proxy-\/agent');}
\DoxyCodeLine{}
\DoxyCodeLine{// SOCKS proxy to connect to}
\DoxyCodeLine{var proxy = process.env.socks\_proxy || 'socks://127.0.0.1:9050';}
\DoxyCodeLine{console.log('using proxy server \%j', proxy);}
\DoxyCodeLine{}
\DoxyCodeLine{// HTTP endpoint for the proxy to connect to}
\DoxyCodeLine{var endpoint = process.argv[2] || 'http://nodejs.org/api/';}
\DoxyCodeLine{console.log('attempting to GET \%j', endpoint);}
\DoxyCodeLine{var opts = url.parse(endpoint);}
\DoxyCodeLine{}
\DoxyCodeLine{// create an instance of the `SocksProxyAgent` class with the proxy server information}
\DoxyCodeLine{var agent = new SocksProxyAgent(proxy);}
\DoxyCodeLine{opts.agent = agent;}
\DoxyCodeLine{}
\DoxyCodeLine{http.get(opts, function (res) \{}
\DoxyCodeLine{  console.log('"{}response"{} event!', res.headers);}
\DoxyCodeLine{  res.pipe(process.stdout);}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_socks_proxy_agent_README_autotoc_md28209}{}\doxysubsubsection{$<$tt$>$https$<$/tt$>$ module example}\label{md_sfcode_node_modules_socks_proxy_agent_README_autotoc_md28209}

\begin{DoxyCode}{0}
\DoxyCodeLine{var url = require('url');}
\DoxyCodeLine{var https = require('https');}
\DoxyCodeLine{var SocksProxyAgent = require('socks-\/proxy-\/agent');}
\DoxyCodeLine{}
\DoxyCodeLine{// SOCKS proxy to connect to}
\DoxyCodeLine{var proxy = process.env.socks\_proxy || 'socks://127.0.0.1:9050';}
\DoxyCodeLine{console.log('using proxy server \%j', proxy);}
\DoxyCodeLine{}
\DoxyCodeLine{// HTTP endpoint for the proxy to connect to}
\DoxyCodeLine{var endpoint = process.argv[2] || 'https://encrypted.google.com/';}
\DoxyCodeLine{console.log('attempting to GET \%j', endpoint);}
\DoxyCodeLine{var opts = url.parse(endpoint);}
\DoxyCodeLine{}
\DoxyCodeLine{// create an instance of the `SocksProxyAgent` class with the proxy server information}
\DoxyCodeLine{var agent = new SocksProxyAgent(proxy);}
\DoxyCodeLine{opts.agent = agent;}
\DoxyCodeLine{}
\DoxyCodeLine{https.get(opts, function (res) \{}
\DoxyCodeLine{  console.log('"{}response"{} event!', res.headers);}
\DoxyCodeLine{  res.pipe(process.stdout);}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_socks_proxy_agent_README_autotoc_md28210}{}\doxysubsubsection{$<$tt$>$ws$<$/tt$>$ Web\+Socket connection example}\label{md_sfcode_node_modules_socks_proxy_agent_README_autotoc_md28210}

\begin{DoxyCode}{0}
\DoxyCodeLine{var WebSocket = require('ws');}
\DoxyCodeLine{var SocksProxyAgent = require('socks-\/proxy-\/agent');}
\DoxyCodeLine{}
\DoxyCodeLine{// SOCKS proxy to connect to}
\DoxyCodeLine{var proxy = process.env.socks\_proxy || 'socks://127.0.0.1:9050';}
\DoxyCodeLine{console.log('using proxy server \%j', proxy);}
\DoxyCodeLine{}
\DoxyCodeLine{// WebSocket endpoint for the proxy to connect to}
\DoxyCodeLine{var endpoint = process.argv[2] || 'ws://echo.websocket.org';}
\DoxyCodeLine{console.log('attempting to connect to WebSocket \%j', endpoint);}
\DoxyCodeLine{}
\DoxyCodeLine{// create an instance of the `SocksProxyAgent` class with the proxy server information}
\DoxyCodeLine{var agent = new SocksProxyAgent(proxy);}
\DoxyCodeLine{}
\DoxyCodeLine{// initiate the WebSocket connection}
\DoxyCodeLine{var socket = new WebSocket(endpoint, \{ agent: agent \});}
\DoxyCodeLine{}
\DoxyCodeLine{socket.on('open', function () \{}
\DoxyCodeLine{  console.log('"{}open"{} event!');}
\DoxyCodeLine{  socket.send('hello world');}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{socket.on('message', function (data, flags) \{}
\DoxyCodeLine{  console.log('"{}message"{} event! \%j \%j', data, flags);}
\DoxyCodeLine{  socket.close();}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_socks_proxy_agent_README_autotoc_md28211}{}\doxysection{License}\label{md_sfcode_node_modules_socks_proxy_agent_README_autotoc_md28211}
(The MIT License)

Copyright (c) 2013 Nathan Rajlich $<$\href{mailto:nathan@tootallnate.net}{\texttt{ nathan@tootallnate.\+net}}$>$

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \textquotesingle{}Software\textquotesingle{}), 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 \textquotesingle{}AS IS\textquotesingle{}, 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. 