Working on forwarding HTTP requests

This commit is contained in:
Jacob Windle 2019-01-26 10:19:25 -05:00
parent 42efcb5909
commit 89bd9f9005
3 changed files with 32 additions and 14 deletions

View File

@ -2,6 +2,7 @@ var net = require('net');
var http = require('http'); var http = require('http');
var fs = require('fs'); var fs = require('fs');
var winston = require("winston"); var winston = require("winston");
var rp = require("request-promise");
// Rudimentary logger. // Rudimentary logger.
// TODO - Make this filename configurable. // TODO - Make this filename configurable.
@ -40,8 +41,13 @@ class HttpRequest {
* *
* TODO - Implement me. * TODO - Implement me.
*/ */
async forwardRequest() { forwardRequest(callbackFn) {
console.log("Forwarding.")
http.request({
host: this.attrs.headers.Host,
method: this.attrs.Method,
headers: this.attrs.headers
}, callbackFn);
} }
} }
@ -92,10 +98,10 @@ function startServer() {
parseHttpRequest(c.toString()) parseHttpRequest(c.toString())
.then((req) => { .then((req) => {
req.logSomething(); req.logSomething();
return req; req.forwardRequest((res) => {
}) console.log("Received response");
.then((req) => { console.log(res);
});
}) })
}); });
}) })

27
package-lock.json generated
View File

@ -831,6 +831,11 @@
"tweetnacl": "^0.14.3" "tweetnacl": "^0.14.3"
} }
}, },
"bluebird": {
"version": "3.5.3",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.3.tgz",
"integrity": "sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw=="
},
"body-parser": { "body-parser": {
"version": "1.18.3", "version": "1.18.3",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz",
@ -4300,14 +4305,12 @@
"psl": { "psl": {
"version": "1.1.31", "version": "1.1.31",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.1.31.tgz", "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.31.tgz",
"integrity": "sha1-6aqG0BAbWxBcvpOsa3hM1UcnYYQ=", "integrity": "sha1-6aqG0BAbWxBcvpOsa3hM1UcnYYQ="
"dev": true
}, },
"punycode": { "punycode": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
"integrity": "sha1-tYsBCsQMIsVldhbI0sLALHv0eew=", "integrity": "sha1-tYsBCsQMIsVldhbI0sLALHv0eew="
"dev": true
}, },
"qs": { "qs": {
"version": "6.5.2", "version": "6.5.2",
@ -4518,11 +4521,21 @@
} }
} }
}, },
"request-promise": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/request-promise/-/request-promise-4.2.2.tgz",
"integrity": "sha1-0epG1lSm7k+O5qT+oQGMIpEZBLQ=",
"requires": {
"bluebird": "^3.5.0",
"request-promise-core": "1.1.1",
"stealthy-require": "^1.1.0",
"tough-cookie": ">=2.3.3"
}
},
"request-promise-core": { "request-promise-core": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.1.tgz", "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.1.tgz",
"integrity": "sha1-Pu4AssWqgyOc+wTFcA2jb4HNCLY=", "integrity": "sha1-Pu4AssWqgyOc+wTFcA2jb4HNCLY=",
"dev": true,
"requires": { "requires": {
"lodash": "^4.13.1" "lodash": "^4.13.1"
} }
@ -5293,8 +5306,7 @@
"stealthy-require": { "stealthy-require": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz", "resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz",
"integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=", "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks="
"dev": true
}, },
"string-length": { "string-length": {
"version": "2.0.0", "version": "2.0.0",
@ -5453,7 +5465,6 @@
"version": "2.5.0", "version": "2.5.0",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz",
"integrity": "sha1-zZ+yoKodWhK0c72fuW+j3P9lreI=", "integrity": "sha1-zZ+yoKodWhK0c72fuW+j3P9lreI=",
"dev": true,
"requires": { "requires": {
"psl": "^1.1.28", "psl": "^1.1.28",
"punycode": "^2.1.1" "punycode": "^2.1.1"

View File

@ -11,6 +11,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"express": "^4.16.4", "express": "^4.16.4",
"request-promise": "^4.2.2",
"winston": "^3.1.0" "winston": "^3.1.0"
}, },
"devDependencies": { "devDependencies": {