mirror of
git://git.psyced.org/git/psyced
synced 2024-08-15 03:25:10 +00:00
support more than HTTP/1.0
This commit is contained in:
parent
3786072189
commit
7b2931d8ee
1 changed files with 34 additions and 27 deletions
|
@ -18,7 +18,7 @@ volatile int length;
|
||||||
// to predefine some functions.
|
// to predefine some functions.
|
||||||
//
|
//
|
||||||
// quite stupid indeed, as they don't got any modifiers or whatever :)
|
// quite stupid indeed, as they don't got any modifiers or whatever :)
|
||||||
parse_url(input);
|
parse_request(input);
|
||||||
parse_header(input);
|
parse_header(input);
|
||||||
parse_body(input);
|
parse_body(input);
|
||||||
devNull();
|
devNull();
|
||||||
|
@ -45,7 +45,7 @@ logon() {
|
||||||
// so we would have to push large files in chunks
|
// so we would have to push large files in chunks
|
||||||
// using heart_beat() or something like that TODO
|
// using heart_beat() or something like that TODO
|
||||||
|
|
||||||
next_input_to(#'parse_url);
|
next_input_to(#'parse_request);
|
||||||
call_out(#'timeout, 23);
|
call_out(#'timeout, 23);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,10 +59,6 @@ disconnected(remainder) {
|
||||||
// gets called from async apps
|
// gets called from async apps
|
||||||
done() { quit(); }
|
done() { quit(); }
|
||||||
|
|
||||||
void create() {
|
|
||||||
if (clonep(ME)) headers = ([ ]);
|
|
||||||
}
|
|
||||||
|
|
||||||
parse_wait(null) { // waiting to send my error message here
|
parse_wait(null) { // waiting to send my error message here
|
||||||
if (null == "") {
|
if (null == "") {
|
||||||
http_error("HTTP/1.0", 405, "Invalid Request (Welcome Proxyscanner)");
|
http_error("HTTP/1.0", 405, "Invalid Request (Welcome Proxyscanner)");
|
||||||
|
@ -71,25 +67,38 @@ parse_wait(null) { // waiting to send my error message here
|
||||||
next_input_to(#'parse_wait);
|
next_input_to(#'parse_wait);
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_url(input) {
|
parse_request(input) {
|
||||||
P3(("=== HTTP got: %O\n", input))
|
// reset state. in case we support HTTP/1.1. do we?
|
||||||
unless (sscanf(input, "%s%t%s%tHTTP/%s", method, url, prot)) quit();
|
method = item = url = prot = body = qs = 0;
|
||||||
switch (method) {
|
headers = ([]);
|
||||||
case "CONNECT":
|
P2(("=== HTTP got: %O from %s\n", input, query_ip_name(ME)))
|
||||||
next_input_to(#'parse_wait);
|
if (!input || input=="") {
|
||||||
return;
|
// should return error?
|
||||||
case "GET":
|
input_to(#'parse_request); // lets just ignore the empty line
|
||||||
case "POST":
|
return 1;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
quit();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
input = explode(input, " ");
|
||||||
prot = "HTTP/" + prot;
|
switch(sizeof(input)) {
|
||||||
|
default:
|
||||||
P2(("=== HTTP user requested url: %O\n", url))
|
prot = input[2];
|
||||||
next_input_to(#'parse_header);
|
next_input_to(#'parse_header);
|
||||||
|
case 2:
|
||||||
|
// earlier HTTP versions have no headers
|
||||||
|
// ok, it's excentric to support HTTP/0.9 but
|
||||||
|
// it is practical for debugging and doesn't
|
||||||
|
// cost us a lot extra effort
|
||||||
|
url = input[1];
|
||||||
|
unless (sscanf(url, "%s?%s", item, qs)) item = url;
|
||||||
|
method = lower_case(input[0]);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
// should return error!
|
||||||
|
quit();
|
||||||
|
}
|
||||||
|
P4(("=== HTTP user requested url: %O\n", url))
|
||||||
|
if (method == "connect") next_input_to(#'parse_wait);
|
||||||
|
else if (!prot) body(); // HTTP/0.9 has no headers
|
||||||
|
else next_input_to(#'parse_header);
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_header(input) {
|
parse_header(input) {
|
||||||
|
@ -156,11 +165,9 @@ process() {
|
||||||
headers["cookie"] = cook;
|
headers["cookie"] = cook;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (sscanf(url, "%s?%s", item, qs)) {
|
if (qs) {
|
||||||
P3(("got query: %O\n", qs))
|
P3(("got query: %O\n", qs))
|
||||||
query = url_parse_query(query, qs);
|
query = url_parse_query(query, qs);
|
||||||
} else {
|
|
||||||
item = url;
|
|
||||||
}
|
}
|
||||||
if (method == "POST" && headers["content-type"] == "application/x-www-form-urlencoded") {
|
if (method == "POST" && headers["content-type"] == "application/x-www-form-urlencoded") {
|
||||||
query = url_parse_query(query, body);
|
query = url_parse_query(query, body);
|
||||||
|
|
Loading…
Reference in a new issue