diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-10-09 09:33:08 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-10-09 09:33:08 -0700 |
commit | 07d382d611458245b521ce79f2b9bb956a58468a (patch) | |
tree | 17e3309b42af77bf9c390022f1b5033bbd827fde /src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs | |
parent | 50585d83046b7950ad3efd8385eba05c4d1dec05 (diff) | |
download | DotNetOpenAuth-07d382d611458245b521ce79f2b9bb956a58468a.zip DotNetOpenAuth-07d382d611458245b521ce79f2b9bb956a58468a.tar.gz DotNetOpenAuth-07d382d611458245b521ce79f2b9bb956a58468a.tar.bz2 |
Added OutgoingWebResponse.AsHttpResponseMessage extension method.
Diffstat (limited to 'src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs')
-rw-r--r-- | src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs index 5390da5..ab56d8b 100644 --- a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs +++ b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs @@ -15,6 +15,9 @@ namespace DotNetOpenAuth.Messaging { using System.IO.Compression; using System.Linq; using System.Net; +#if CLR4 + using System.Net.Http; +#endif using System.Net.Mime; using System.Runtime.Serialization.Json; using System.Security; @@ -161,6 +164,28 @@ namespace DotNetOpenAuth.Messaging { return new OutgoingWebResponseActionResult(response); } +#if CLR4 + /// <summary> + /// Transforms an OutgoingWebResponse to a Web API-friendly HttpResponseMessage. + /// </summary> + /// <param name="outgoingResponse">The response to send to the user agent.</param> + /// <returns>The <see cref="HttpResponseMessage"/> instance to be returned by the Web API method.</returns> + public static HttpResponseMessage AsHttpResponseMessage(this OutgoingWebResponse outgoingResponse) { + HttpResponseMessage response = new HttpResponseMessage(outgoingResponse.Status) { + Content = new StreamContent(outgoingResponse.ResponseStream) + }; + + var responseHeaders = outgoingResponse.Headers; + foreach (var header in responseHeaders.AllKeys) { + if (!response.Headers.TryAddWithoutValidation(header, responseHeaders[header])) { + response.Content.Headers.TryAddWithoutValidation(header, responseHeaders[header]); + } + } + + return response; + } +#endif + /// <summary> /// Gets the original request URL, as seen from the browser before any URL rewrites on the server if any. /// Cookieless session directory (if applicable) is also included. |