SYSLOG("connection head: " + (tmp?tmp:"")  + " [keep-alive: " + keep_alive + "]\n");
static object create_request(string str){	object request;	string	cmd, ruri, ver, head, file, authstr, tmp;	request = new_object(HTTP_REQUEST);	if(!str||sscanf(str, "%s %s HTTP/%s\r\n%s", cmd, ruri, ver, head) !=4 ) {		if(sscanf(str, "%s %s HTTP/%s\n%s", cmd, ruri, ver, head) != 4) {			request->set_badrequest(TRUE);			SYSLOG("create_request(): Bad request?\n");			return request;		}	}	request->set_headers(head);	request->set_command(cmd);	request->set_protocol_version(ver);	request->set_client_ip_name(ip_name());	request->set_client_ip_number(ip_number());	request->set_port(get_port());	if(request->set_uri(ruri) == FALSE) {		request->set_badrequest(TRUE);		return request;	}	if(ver == "1.1" && request->get_header("Host") == nil) {		request->set_badrequest(TRUE);		return request;	} else if(request->get_header("Host") == nil) {		/* Cheating, but we always want a Host header. */		request->set_header("Host", "");	} else if(index_of(0, request->get_header("Host"), ":") != -1) {		/* *sigh* Ugly fix. 		 * TODO: This will not work under INET6		 */		request->set_header("Host", 				explode(request->get_header("Host"), ":")[0]);	}	/* TODO: Must deal with more connection-types, this is a hack */	if((tmp = request->get_header("Connection")) && 			lower_case(tmp) == "keep-alive") {		keep_alive = TRUE;	} else {		keep_alive = FALSE;	}	SYSLOG("connection head: " + (tmp?tmp:"")  + 		   " [keep-alive: " + keep_alive + "]\n");	/* Authenticate user (if any) authenticate() returns user to log in */	if(request->get_header("Authorization") && get_name() == HTTP_ANON_USER &&				(authstr = authend->authenticate(request)) && strlen(str)) {		SYSLOG("logging in '" + authstr + "'...\n");		user::login( authstr, 1 );		SYSLOG("logged in name is: " + query_name() + "\n");		request->set_header("Authorization", "[secret]");		request->set_authenticated( get_name() ? get_name() : "" );		clone_tools();			} else if(commandcount() == 0) {		clone_tools();	}	/* POST requests don't need to set content-length in headers */	if((request->get_header("Content-Length") 			&& request->get_header("Content-Length") != "0") 			|| cmd == "POST") {		int len;		string content;		object ob;			if(request->get_header("Content-Length")) {			len = (int)request->get_header("Content-Length");		} else {			len = 0;		}		SYSLOG("Claimed tot: " + len + " bytes (got: "+strlen(str)+")\n");		if(sscanf(str, "%*s" + CRLF + CRLF + "%s", content) == 2) {			SYSLOG("adding some content\n");		} else if(cmd == "POST") {			SYSLOG("expecting content\n");		} else {			/* Headers did not end with 2*CRLF, bad request */			SYSLOG("malformed request\n");			request->set_badrequest(TRUE);			return request;		}		SYSLOG("expecting more content\n");		ob = set_incoming();		ob->set_request(request);		if(content != nil && strlen(content)) {			request->add_content(content);			receive_pending( request->content_tostring() );		} else {			SYSLOG("no content with request\n");		}		return nil;	}	return request;}