using System; using System.Collections.Specialized; using System.Text; using System.Net; using System.Diagnostics; using DotNetOpenId.Provider; using System.IO; using System.Web; namespace DotNetOpenId { /// /// Encodes messages into instances /// that can be interpreted by the host web site. /// internal class MessageEncoder { /// /// The HTTP Content-Type to use in Key-Value Form responses. /// const string KeyValueFormContentType = "application/x-openid-kvf"; /// /// The maximum allowable size for a 301 Redirect response before we send /// a 200 OK response with a scripted form POST with the parameters instead /// in order to ensure successfully sending a large payload to another server /// that might have a maximum allowable size restriction on its GET request. /// internal static int GetToPostThreshold = 2 * 1024; // 2KB, recommended by OpenID group // We are intentionally using " instead of the html single quote ' below because // the HtmlEncode'd values that we inject will only escape the double quote, so // only the double-quote used around these values is safe. const string FormPostFormat = @"
{1}
"; /// /// Encodes messages into instances. /// public virtual Response Encode(IEncodable message) { if (message == null) throw new ArgumentNullException("message"); EncodingType encode_as = message.EncodingType; Response wr; WebHeaderCollection headers = new WebHeaderCollection(); switch (encode_as) { case EncodingType.DirectResponse: Logger.DebugFormat("Sending direct message response:{0}{1}", Environment.NewLine, Util.ToString(message.EncodedFields)); HttpStatusCode code = (message is Exception) ? HttpStatusCode.BadRequest : HttpStatusCode.OK; // Key-Value Encoding is how response bodies are sent. // Setting the content-type to something other than text/html or text/plain // prevents free hosted sites like GoDaddy's from automatically appending // the