public HTTPRequest(string method_, string uri_, string version_="HTTP/1.0", HTTPHeaders headers_=null,
byte[] body_=null, string remote_ip_=null, string protocol_=null, string host_=null,
string files=null, HTTPConnection connection_=null)
{
method = method_;
uri = uri_;
version = version_;
headers = headers_ ?? new HTTPHeaders();
body = body_ ?? new byte[] {};
if (connection != null && connection.xheaders)
{
// Squid uses X-Forwarded-For, others use X-Real-Ip
remote_ip = headers.get(
"X-Real-Ip", headers.get("X-Forwarded-For", remote_ip_));
if (!_valid_ip(remote_ip))
remote_ip = remote_ip_;
// AWS uses X-Forwarded-Proto
protocol = headers.get(
"X-Scheme", headers.get("X-Forwarded-Proto", protocol_));
if (protocol != "http" && protocol != "https")
protocol = "http";
}
else
{
remote_ip = remote_ip_;
if (protocol_ != null)
protocol = protocol_;
//todo ssl else if (connection != null && isinstance(connection.stream, iostream.SSLIOStream):
// protocol = "https"
else
protocol = "http";
}
host = host_ ?? headers.get("Host") ?? "127.0.0.1";
//todo files = files_ ?? {}
connection = connection_;
_start_time = DateTime.Now;
_finish_time = null;
var parts = uri.Split(new char[] { '?' }, 2);
path = parts.Length > 0 ? parts[0] : null;
query = parts.Length > 1 ? parts[1] : null;
var arguments_ = System.Web.HttpUtility.ParseQueryString(query ?? "");// parse_qs_bytes(query)
arguments = new Dictionary<string, string[]>();
foreach(var name in arguments_.AllKeys)
{
var values = arguments_.GetValues(name);
if(values != null)
arguments[name] = values;
}
}