Skip to content
This repository has been archived by the owner on Sep 13, 2020. It is now read-only.

Commit

Permalink
Allow npm install globally and refactor the README
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrus-and committed Jul 7, 2015
1 parent fd123d8 commit a396655
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
40 changes: 26 additions & 14 deletions README.md
Expand Up @@ -6,22 +6,42 @@ gproxy exploits a Google web service hosted at
fetch user-provided content, e.g., to load images by URL in Google Documents) to
proxy arbitrary HTTP(S) traffic.

Installation
------------

Install with:

npm install -g git://github.com/cyrus-and/gproxy.git

Note that a global installation is not mandatory, just start the proxy with `npm
start` from this directory.

Usage
-----

1. Generate a self-signed certificate (or skip this step and use the one
provided):
bundled):

openssl req -x509 -newkey rsa:2048 -nodes -days 3650 \
-subj '/CN=localhost' -keyout key.pem -out cert.pem

2. Start the proxy:
Certificates (`key.pem` and `cert.pem`) in the current working directory will
have the precedence over the one bundled.

2. Start the proxy, optionally also specifying host and port. By default gproxy
listens on `localhost:8080` but this can be changed by setting two
environment variables: `GPROXY_HOST` and `GPROXY_PORT`. For example with:

npm start
export GPROXY_HOST=0.0.0.0
export GPROXY_PORT=1234
gproxy

3. Use `http://localhost:8080` as a proxy server in your client configuration
for both HTTP and HTTPS traffic. Most programs look for specific environment
variables like `http_proxy` and `https_proxy`. With Bash just:
gproxy will listen on all the local interfaces on port `1234`.

3. Use `http://localhost:8080` (or whatever has been chosen) as a proxy server
in your client configuration for both HTTP and HTTPS traffic. Most programs
look for specific environment variables like `http_proxy` and
`https_proxy`. With Bash just:

export http{,s}_proxy=http://localhost:8080

Expand All @@ -32,14 +52,6 @@ Usage
curl -k https://example.com
wget --no-check-certificate https://example.com

By default gproxy listens on `localhost:8080` but this can be changed by setting
two environment variables: `GPROXY_HOST` and `GPROXY_PORT`. For example with:

export GPROXY_HOST=0.0.0.0
export GPROXY_PORT=1234

gproxy will listen on all the local interfaces on port 1234.

Caveats
-------

Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -2,5 +2,6 @@
"name": "gproxy",
"author": "Andrea Cardaci <cyrus.and@gmail.com>",
"description": "googleusercontent.com as HTTP(S) proxy",
"version": "0.0.0"
"version": "0.0.0",
"bin": "./server.js"
}
23 changes: 18 additions & 5 deletions server.js
@@ -1,7 +1,13 @@
#!/usr/bin/env node

var fs = require('fs');
var net = require('net');
var http = require('http');
var https = require('https');
var path = require('path');

var key_name = 'key.pem';
var cert_name = 'cert.pem';

var host = process.env.GPROXY_HOST || 'localhost';
var port = process.env.GPROXY_PORT || 8080;
Expand Down Expand Up @@ -42,11 +48,18 @@ function request_handler(request, response) {
request.pipe(proxy_request);
}

try {
var key = fs.readFileSync(key_name);
var cert = fs.readFileSync(cert_name);
} catch (err) {
console.log('# falling back to the bundled certificate');
process.chdir(__dirname);
key = fs.readFileSync(key_name);
cert = fs.readFileSync(cert_name);
}

var http_server = http.createServer();
var https_server = https.createServer({
'key': fs.readFileSync('key.pem'),
'cert': fs.readFileSync('cert.pem')
});
var https_server = https.createServer({'key': key, 'cert': cert});

http_server.on('connect', connect_handler);
http_server.on('request', request_handler);
Expand All @@ -55,6 +68,6 @@ https_server.on('request', request_handler);
http_server.listen(port, host, function () {
https_server.listen(0, 'localhost', function () {
https_port = https_server.address().port;
console.log('# gproxy listening on ' + host + ':' + port);
console.log('# listening on ' + host + ':' + port);
});
});

0 comments on commit a396655

Please sign in to comment.