private void BuildServerVariables(HttpClient client)
{
ServerVariables = new NameValueCollection();
// Add all headers.
var allHttp = new StringBuilder();
var allRaw = new StringBuilder();
foreach (var item in client.Headers)
{
ServerVariables[item.Key] = item.Value;
string httpKey = "HTTP_" + (item.Key.Replace('-', '_')).ToUpperInvariant();
ServerVariables[httpKey] = item.Value;
allHttp.Append(httpKey);
allHttp.Append('=');
allHttp.Append(item.Value);
allHttp.Append("\r\n");
allRaw.Append(item.Key);
allRaw.Append('=');
allRaw.Append(item.Value);
allRaw.Append("\r\n");
}
ServerVariables["ALL_HTTP"] = allHttp.ToString();
ServerVariables["ALL_RAW"] = allRaw.ToString();
ServerVariables["CONTENT_LENGTH"] = ContentLength.ToString(CultureInfo.InvariantCulture);
ServerVariables["CONTENT_TYPE"] = ContentType;
ServerVariables["LOCAL_ADDR"] = client.Server.EndPoint.Address.ToString();
ServerVariables["PATH_INFO"] = Path;
string[] parts = client.Request.Split(new[] { '?' }, 2);
ServerVariables["QUERY_STRING"] = parts.Length == 2 ? parts[1] : "";
ServerVariables["REMOTE_ADDR"] = UserHostAddress;
ServerVariables["REMOTE_HOST"] = UserHostName;
ServerVariables["REMOTE_PORT"] = null;
ServerVariables["REQUEST_METHOD"] = RequestType;
ServerVariables["SCRIPT_NAME"] = Path;
ServerVariables["SERVER_NAME"] = client.Server.ServerUtility.MachineName;
ServerVariables["SERVER_PORT"] = client.Server.EndPoint.Port.ToString(CultureInfo.InvariantCulture);
ServerVariables["SERVER_PROTOCOL"] = client.Protocol;
ServerVariables["URL"] = Path;
}