support more than HTTP/1.0

This commit is contained in:
psyc://psyced.org/~lynX 2011-08-27 12:58:38 +02:00
parent 3786072189
commit 7b2931d8ee

View File

@ -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; }
input = explode(input, " ");
switch(sizeof(input)) {
default: default:
quit(); prot = input[2];
return; next_input_to(#'parse_header);
} case 2:
// earlier HTTP versions have no headers
prot = "HTTP/" + prot; // ok, it's excentric to support HTTP/0.9 but
// it is practical for debugging and doesn't
P2(("=== HTTP user requested url: %O\n", url)) // cost us a lot extra effort
next_input_to(#'parse_header); 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);