//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOAuth.Messaging { using System; using System.Net; using System.Web; /// /// A protocol message (request or response) that passes between Consumer and Service Provider /// via the user agent using a redirect or form POST submission, /// OR a direct message response. /// /// /// An instance of this type describes the HTTP response that must be sent /// in response to the current HTTP request. /// It is important that this response make up the entire HTTP response. /// A hosting ASPX page should not be allowed to render its normal HTML output /// after this response is sent. The normal rendered output of an ASPX page /// can be canceled by calling after this message /// is sent on the response stream. /// public class Response { /// /// Gets the headers that must be included in the response to the user agent. /// /// /// The headers in this collection are not meant to be a comprehensive list /// of exactly what should be sent, but are meant to augment whatever headers /// are generally included in a typical response. /// public WebHeaderCollection Headers { get; internal set; } /// /// Gets the body of the HTTP response. /// public byte[] Body { get; internal set; } /// /// Gets the HTTP status code to use in the HTTP response. /// public HttpStatusCode Status { get; internal set; } /// /// Gets or sets a reference to the actual protocol message that /// is being sent via the user agent. /// internal IProtocolMessage OriginalMessage { get; set; } /// /// Automatically sends the appropriate response to the user agent. /// Requires a current HttpContext. /// public void Send() { if (HttpContext.Current == null) { throw new InvalidOperationException(Strings.CurrentHttpContextRequired); } HttpContext.Current.Response.Clear(); HttpContext.Current.Response.StatusCode = (int)this.Status; MessagingUtilities.ApplyHeadersToResponse(this.Headers, HttpContext.Current.Response); if (this.Body != null && this.Body.Length > 0) { HttpContext.Current.Response.OutputStream.Write(this.Body, 0, this.Body.Length); HttpContext.Current.Response.OutputStream.Flush(); } HttpContext.Current.Response.OutputStream.Close(); HttpContext.Current.Response.End(); } } }