summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2012-01-22 08:51:59 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2012-01-29 10:38:19 -0800
commitab5d29be79214e36d01031cc638a3bd935adb24a (patch)
tree1db5fc78344463acf4d71a0f230b8524c076622a /src
parent777f7a2fa69ec2319c23397c8a2ae02966097617 (diff)
downloadDotNetOpenAuth-ab5d29be79214e36d01031cc638a3bd935adb24a.zip
DotNetOpenAuth-ab5d29be79214e36d01031cc638a3bd935adb24a.tar.gz
DotNetOpenAuth-ab5d29be79214e36d01031cc638a3bd935adb24a.tar.bz2
Added more support for HttpContextBase, HttpResponseBase, etc.
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs2
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/OutgoingWebResponse.cs48
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs6
3 files changed, 50 insertions, 6 deletions
diff --git a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
index 9277734..2a94791 100644
--- a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
@@ -906,7 +906,7 @@ namespace DotNetOpenAuth.Messaging {
/// </summary>
/// <param name="headers">The headers to add.</param>
/// <param name="response">The <see cref="HttpResponse"/> instance to set the appropriate values to.</param>
- internal static void ApplyHeadersToResponse(WebHeaderCollection headers, HttpResponse response) {
+ internal static void ApplyHeadersToResponse(WebHeaderCollection headers, HttpResponseBase response) {
Requires.NotNull(headers, "headers");
Requires.NotNull(response, "response");
diff --git a/src/DotNetOpenAuth.Core/Messaging/OutgoingWebResponse.cs b/src/DotNetOpenAuth.Core/Messaging/OutgoingWebResponse.cs
index 003cac8..026b7c2 100644
--- a/src/DotNetOpenAuth.Core/Messaging/OutgoingWebResponse.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/OutgoingWebResponse.cs
@@ -142,6 +142,18 @@ namespace DotNetOpenAuth.Messaging {
/// <exception cref="ThreadAbortException">Typically thrown by ASP.NET in order to prevent additional data from the page being sent to the client and corrupting the response.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual void Send(HttpContext context) {
+ this.Respond(new HttpContextWrapper(context), true);
+ }
+
+ /// <summary>
+ /// Automatically sends the appropriate response to the user agent
+ /// and ends execution on the current page or handler.
+ /// </summary>
+ /// <param name="context">The context of the HTTP request whose response should be set.
+ /// Typically this is <see cref="HttpContext.Current"/>.</param>
+ /// <exception cref="ThreadAbortException">Typically thrown by ASP.NET in order to prevent additional data from the page being sent to the client and corrupting the response.</exception>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public virtual void Send(HttpContextBase context) {
this.Respond(context, true);
}
@@ -176,7 +188,25 @@ namespace DotNetOpenAuth.Messaging {
/// ASP.NET will render HTML after the protocol message has been sent, which will corrupt the response.
/// Use the <see cref="Send()"/> method instead for web forms.
/// </remarks>
- public virtual void Respond(HttpContext context) {
+ public void Respond(HttpContext context) {
+ Requires.NotNull(context, "context");
+ this.Respond(new HttpContextWrapper(context));
+ }
+
+ /// <summary>
+ /// Automatically sends the appropriate response to the user agent
+ /// and signals ASP.NET to short-circuit the page execution pipeline
+ /// now that the response has been completed.
+ /// Not safe to call from ASP.NET web forms.
+ /// </summary>
+ /// <param name="context">The context of the HTTP request whose response should be set.
+ /// Typically this is <see cref="HttpContext.Current"/>.</param>
+ /// <remarks>
+ /// This call is not safe to make from an ASP.NET web form (.aspx file or code-behind) because
+ /// ASP.NET will render HTML after the protocol message has been sent, which will corrupt the response.
+ /// Use the <see cref="Send()"/> method instead for web forms.
+ /// </remarks>
+ public virtual void Respond(HttpContextBase context) {
Requires.NotNull(context, "context");
this.Respond(context, false);
@@ -264,7 +294,21 @@ namespace DotNetOpenAuth.Messaging {
/// <param name="endRequest">If set to <c>false</c>, this method calls
/// <see cref="HttpApplication.CompleteRequest"/> rather than <see cref="HttpResponse.End"/>
/// to avoid a <see cref="ThreadAbortException"/>.</param>
- protected internal virtual void Respond(HttpContext context, bool endRequest) {
+ protected internal void Respond(HttpContext context, bool endRequest) {
+ this.Respond(new HttpContextWrapper(context), endRequest);
+ }
+
+ /// <summary>
+ /// Automatically sends the appropriate response to the user agent
+ /// and signals ASP.NET to short-circuit the page execution pipeline
+ /// now that the response has been completed.
+ /// </summary>
+ /// <param name="context">The context of the HTTP request whose response should be set.
+ /// Typically this is <see cref="HttpContext.Current"/>.</param>
+ /// <param name="endRequest">If set to <c>false</c>, this method calls
+ /// <see cref="HttpApplication.CompleteRequest"/> rather than <see cref="HttpResponse.End"/>
+ /// to avoid a <see cref="ThreadAbortException"/>.</param>
+ protected internal virtual void Respond(HttpContextBase context, bool endRequest) {
Requires.NotNull(context, "context");
context.Response.Clear();
diff --git a/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs b/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs
index 79751ae..2a683ed 100644
--- a/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs
@@ -98,7 +98,7 @@ namespace DotNetOpenAuth.Test.Messaging {
[TestCase, ExpectedException(typeof(ArgumentNullException))]
public void ApplyHeadersToResponseNullAspNetResponse() {
- MessagingUtilities.ApplyHeadersToResponse(new WebHeaderCollection(), (HttpResponse)null);
+ MessagingUtilities.ApplyHeadersToResponse(new WebHeaderCollection(), (HttpResponseBase)null);
}
[TestCase, ExpectedException(typeof(ArgumentNullException))]
@@ -108,7 +108,7 @@ namespace DotNetOpenAuth.Test.Messaging {
[TestCase, ExpectedException(typeof(ArgumentNullException))]
public void ApplyHeadersToResponseNullHeaders() {
- MessagingUtilities.ApplyHeadersToResponse(null, new HttpResponse(new StringWriter()));
+ MessagingUtilities.ApplyHeadersToResponse(null, new HttpResponseWrapper(new HttpResponse(new StringWriter())));
}
[TestCase]
@@ -116,7 +116,7 @@ namespace DotNetOpenAuth.Test.Messaging {
var headers = new WebHeaderCollection();
headers[HttpResponseHeader.ContentType] = "application/binary";
- var response = new HttpResponse(new StringWriter());
+ var response = new HttpResponseWrapper(new HttpResponse(new StringWriter()));
MessagingUtilities.ApplyHeadersToResponse(headers, response);
Assert.AreEqual(headers[HttpResponseHeader.ContentType], response.ContentType);