Properly parse request headers, use trim for leading whitespace

master
Jacob Windle 2019-01-26 08:09:48 -05:00
parent b89cb298d3
commit cb120763e1
2 changed files with 23 additions and 7 deletions

View File

@ -24,8 +24,8 @@ class HttpRequest {
})
}
forwardRequest() {
async forwardRequest() {
// TODO - rebuild the request and return it to the client.
}
}
@ -34,7 +34,7 @@ class HttpRequest {
* @param {String} bytes
*/
async function parseHttpRequest(bytes) {
let httpRequestAttrs = {headers: ""};
let httpRequestAttrs = {headers: {}};
bytes.split("\r\n").map((row) => {
// Match against HTTP verbs from the first row.
@ -48,11 +48,14 @@ async function parseHttpRequest(bytes) {
return null;
}
httpRequestAttrs["type"] = typeInfo[0];
httpRequestAttrs["path"] = typeInfo[1];
httpRequestAttrs["httpVersion"] = typeInfo[2];
httpRequestAttrs["Method"] = typeInfo[0];
httpRequestAttrs["Path"] = typeInfo[1];
httpRequestAttrs["HttpVersion"] = typeInfo[2];
} else {
httpRequestAttrs.headers = httpRequestAttrs.headers.concat(row + "\r\n");
let currentRow = row.split(":");
console.log(currentRow);
if (currentRow[0] !== '')
httpRequestAttrs.headers[currentRow[0]] = currentRow[1].trim();
}
});
@ -77,6 +80,10 @@ function startServer() {
parseHttpRequest(c.toString())
.then((req) => {
req.logSomething();
return req;
})
.then((req) => {
})
});
})

View File

@ -0,0 +1,9 @@
import requests
# TODO - Make this configurable based on config file test section.
http_proxy = "http://127.0.0.1:8124"
def test_proxy_basic():
resp = requests.get("http://google.com", proxies={"http": http_proxy})