Skip to content

Commit

Permalink
adding raw request and proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
RIAEvangelist committed Sep 12, 2016
1 parent 43d8102 commit ff64273
Show file tree
Hide file tree
Showing 1,779 changed files with 149,132 additions and 14 deletions.
30 changes: 30 additions & 0 deletions example/proxy/basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const util = require( 'util' );
const server=require('../../server/http.js');
//I am using request for simplicty sake here, you can too.
const proxy=require('request');
const config=new server.Config;

config.verbose=true;
config.port=8000;


function gotRequest(request,response,serve){
//google proxy!
console.log(request.uri,request.headers);

serve(
request,
response,
JSON.stringify(
{
uri:request.uri,
headers:request.headers
}
)
);

return true;
}

server.deploy(config);
server.onRawRequest=gotRequest;
37 changes: 37 additions & 0 deletions example/proxy/https-and-http-basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const util = require( 'util' );
const server=require('../../server/http.js');
//I am using request for simplicty sake here, you can too.
const proxy=require('request');
const config=new server.Config;

config.verbose=true;
config.port=8000;
config.https.privateKey = `${__dirname}/../../local-certs/private/server.key`;
config.https.certificate= `${__dirname}/../../local-certs/server.pub`;
config.https.port = 4433;

//lets ignore ssl issues and make a giant security hole since we are proxying https too...
//be careful when proxying ssl. you should actually set your ca and certs properly.
//this is just an example
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

function gotRequest(request,response,serve){
//google proxy!
console.log(request.uri,request.headers);

serve(
request,
response,
JSON.stringify(
{
uri:request.uri,
headers:request.headers
}
)
);

return true;
}

server.deploy(config);
server.onRawRequest=gotRequest;
67 changes: 67 additions & 0 deletions example/proxy/https-and-http-google-proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const util = require( 'util' );
const server=require('../../server/http.js');
//I am using request for simplicty sake here, you can too.
const proxy=require('request');
const config=new server.Config;

config.verbose=true;
config.port=8000;
config.https.privateKey = `${__dirname}/../../local-certs/private/server.key`;
config.https.certificate= `${__dirname}/../../local-certs/server.pub`;
config.https.port = 4433;

//lets ignore ssl issues and make a giant security hole since we are proxying https too...
//be careful when proxying ssl. you should actually set your ca and certs properly.
//this is just an example
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;

function gotRequest(request,response,serve){
//google proxy!
//handle things fast
let encoding='binary';

proxy(
{
url: `${request.uri.protocol}://www.google.com${request.uri.path}${request.uri.search}`,
encoding:encoding
},
function (error, proxiedResponse, proxiedBody) {
if (error) {
request.statusCode=500;
serve(request,response,JSON.stringify(error));
return;
}

if(proxiedResponse.headers['content-type'].indexOf('text/html')>-1){
const position=proxiedBody.match(/<body([^>]*)>/i);

if(position&&position.index){
proxiedBody=proxiedBody.slice(0, position.index+position[0].length) + `
<style>
.proxyBanner{
height:5em;
background:rgb(200,220,240);
font-size:2em;
line-height:5em;
box-shadow:0 0 .5em rgba(0,0,0,.7);
text-align:center;
}
</style>
<section class='proxyBanner'>Welcome to Google!</section>
`+ proxiedBody.slice(position.index+position[0].length)
}
}

response.headers=proxiedResponse.headers;

serve(request,response,proxiedBody);

return;
}
);

return true;
}

server.deploy(config);
server.onRawRequest=gotRequest;
1 change: 1 addition & 0 deletions node_modules/.bin/har-validator

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/sshpk-conv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/sshpk-sign

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/sshpk-verify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions node_modules/ansi-regex/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions node_modules/ansi-regex/license

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

122 changes: 122 additions & 0 deletions node_modules/ansi-regex/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions node_modules/ansi-regex/readme.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions node_modules/ansi-styles/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ff64273

Please sign in to comment.