Properly parse request headers, use trim for leading whitespace
This commit is contained in:
parent
b89cb298d3
commit
cb120763e1
21
index.js
21
index.js
@ -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
|
* @param {String} bytes
|
||||||
*/
|
*/
|
||||||
async function parseHttpRequest(bytes) {
|
async function parseHttpRequest(bytes) {
|
||||||
let httpRequestAttrs = {headers: ""};
|
let httpRequestAttrs = {headers: {}};
|
||||||
|
|
||||||
bytes.split("\r\n").map((row) => {
|
bytes.split("\r\n").map((row) => {
|
||||||
// Match against HTTP verbs from the first row.
|
// Match against HTTP verbs from the first row.
|
||||||
@ -48,11 +48,14 @@ async function parseHttpRequest(bytes) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
httpRequestAttrs["type"] = typeInfo[0];
|
httpRequestAttrs["Method"] = typeInfo[0];
|
||||||
httpRequestAttrs["path"] = typeInfo[1];
|
httpRequestAttrs["Path"] = typeInfo[1];
|
||||||
httpRequestAttrs["httpVersion"] = typeInfo[2];
|
httpRequestAttrs["HttpVersion"] = typeInfo[2];
|
||||||
} else {
|
} 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())
|
parseHttpRequest(c.toString())
|
||||||
.then((req) => {
|
.then((req) => {
|
||||||
req.logSomething();
|
req.logSomething();
|
||||||
|
return req;
|
||||||
|
})
|
||||||
|
.then((req) => {
|
||||||
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -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})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user