summaryrefslogtreecommitdiffstats
path: root/src/DotNetOAuth/Messaging/ProtocolMessageResponse.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOAuth/Messaging/ProtocolMessageResponse.cs')
-rw-r--r--src/DotNetOAuth/Messaging/ProtocolMessageResponse.cs73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/DotNetOAuth/Messaging/ProtocolMessageResponse.cs b/src/DotNetOAuth/Messaging/ProtocolMessageResponse.cs
new file mode 100644
index 0000000..1f2d081
--- /dev/null
+++ b/src/DotNetOAuth/Messaging/ProtocolMessageResponse.cs
@@ -0,0 +1,73 @@
+//-----------------------------------------------------------------------
+// <copyright file="ProtocolMessageResponse.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.Messaging {
+ using System;
+ using System.Net;
+ using System.Web;
+
+ /// <summary>
+ /// 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.
+ /// </summary>
+ /// <remarks>
+ /// <para>An instance of this type describes the HTTP response that must be sent
+ /// in response to the current HTTP request.</para>
+ /// <para>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 <see cref="HttpResponse.End"/> after this message
+ /// is sent on the response stream.</para>
+ /// </remarks>
+ public class ProtocolMessageResponse {
+ /// <summary>
+ /// Gets the headers that must be included in the response to the user agent.
+ /// </summary>
+ /// <remarks>
+ /// 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.
+ /// </remarks>
+ public WebHeaderCollection Headers { get; internal set; }
+
+ /// <summary>
+ /// Gets the body of the HTTP response.
+ /// </summary>
+ public byte[] Body { get; internal set; }
+
+ /// <summary>
+ /// Gets the HTTP status code to use in the HTTP response.
+ /// </summary>
+ public HttpStatusCode Status { get; internal set; }
+
+ /// <summary>
+ /// Gets or sets a reference to the actual protocol message that
+ /// is being sent via the user agent.
+ /// </summary>
+ internal IProtocolMessage OriginalMessage { get; set; }
+
+ /// <summary>
+ /// Automatically sends the appropriate response to the user agent.
+ /// Requires a current HttpContext.
+ /// </summary>
+ 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();
+ }
+ }
+}