diff --git a/Site5/Security/BitId.aspx.cs b/Site5/Security/BitId.aspx.cs index cb02c9b1..0d2e5b23 100644 --- a/Site5/Security/BitId.aspx.cs +++ b/Site5/Security/BitId.aspx.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Web; +using System.Web.ExtensionMethods; using System.Web.Services; using System.Web.UI; using System.Web.UI.WebControls; @@ -13,6 +15,7 @@ namespace Swarmops.Security { protected void Page_Load(object sender, EventArgs e) { + Persistence.Key["BitIdTest_Raw"] = Request.ToRaw(); } // ReSharper disable once InconsistentNaming @@ -24,4 +27,79 @@ namespace Swarmops.Security Persistence.Key["BitIdText_Signature"] = signature; } } -} \ No newline at end of file +} + + + +namespace System.Web.ExtensionMethods +{ + /// + /// Extension methods for HTTP Request. + /// + /// See the HTTP 1.1 specification http://www.w3.org/Protocols/rfc2616/rfc2616.html + /// for details of implementation decisions. + /// + /// + public static class HttpRequestExtensions + { + + /// + /// Dump the raw http request to a string. + /// + /// The that should be dumped. + /// The raw HTTP request. + public static string ToRaw(this HttpRequest request) + { + StringWriter writer = new StringWriter(); + + WriteStartLine(request, writer); + WriteHeaders(request, writer); + WriteBody(request, writer); + + return writer.ToString(); + } + + public static string GetBody(this HttpRequest request) + { + StringWriter writer = new StringWriter(); + WriteBody(request, writer); + + return writer.ToString(); + } + + private static void WriteStartLine(HttpRequest request, StringWriter writer) + { + const string SPACE = " "; + + writer.Write(request.HttpMethod); + writer.Write(SPACE + request.Url); + writer.WriteLine(SPACE + request.ServerVariables["SERVER_PROTOCOL"]); + } + + + private static void WriteHeaders(HttpRequest request, StringWriter writer) + { + foreach (string key in request.Headers.AllKeys) + { + writer.WriteLine(string.Format("{0}: {1}", key, request.Headers[key])); + } + + writer.WriteLine(); + } + + + private static void WriteBody(HttpRequest request, StringWriter writer) + { + StreamReader reader = new StreamReader(request.InputStream); + + try + { + string body = reader.ReadToEnd(); + writer.WriteLine(body); + } + finally + { + reader.BaseStream.Position = 0; + } + } +}