summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2013-01-13 20:08:23 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2013-01-13 20:08:23 -0800
commitdc4ea8b94bdff46e230c2a8e2bde811cb9c8cff8 (patch)
tree6644fc98becbcc06cfd8e7b7a1198bb55c35049a /src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
parent6ab89555a4713182f7a7381d2f73913f3ad87b3b (diff)
downloadDotNetOpenAuth-dc4ea8b94bdff46e230c2a8e2bde811cb9c8cff8.zip
DotNetOpenAuth-dc4ea8b94bdff46e230c2a8e2bde811cb9c8cff8.tar.gz
DotNetOpenAuth-dc4ea8b94bdff46e230c2a8e2bde811cb9c8cff8.tar.bz2
OAuth2.Client builds.
Diffstat (limited to 'src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs')
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
index d9fedf2..4b04052 100644
--- a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
@@ -15,6 +15,7 @@ namespace DotNetOpenAuth.Messaging {
using System.Linq;
using System.Net;
using System.Net.Http;
+ using System.Net.Http.Headers;
using System.Net.Mime;
using System.Runtime.Serialization.Json;
using System.Security;
@@ -625,6 +626,26 @@ namespace DotNetOpenAuth.Messaging {
}
/// <summary>
+ /// Adds a Set-Cookie HTTP header for the specified cookie.
+ /// WARNING: support for cookie properties is currently VERY LIMITED.
+ /// </summary>
+ internal static void SetCookie(this HttpResponseHeaders headers, Cookie cookie) {
+ Requires.NotNull(headers, "headers");
+ Requires.NotNull(cookie, "cookie");
+
+ var cookieBuilder = new StringBuilder(HttpUtility.UrlEncode(cookie.Name) + "=" + HttpUtility.UrlEncode(cookie.Value));
+ if (cookie.HttpOnly) {
+ cookieBuilder.Append("; HttpOnly");
+ }
+
+ if (cookie.Secure) {
+ cookieBuilder.Append("; Secure");
+ }
+
+ headers.Add("Set-Cookie", cookieBuilder.ToString());
+ }
+
+ /// <summary>
/// Gets a random string made up of a given set of allowable characters.
/// </summary>
/// <param name="length">The length of the desired random string.</param>
@@ -1525,6 +1546,27 @@ namespace DotNetOpenAuth.Messaging {
}
}
+ internal static Uri GetDirectUriRequest(this HttpResponseMessage response) {
+ Requires.NotNull(response, "response");
+ Requires.Argument(
+ response.StatusCode == HttpStatusCode.Redirect || response.StatusCode == HttpStatusCode.RedirectKeepVerb
+ || response.StatusCode == HttpStatusCode.RedirectMethod || response.StatusCode == HttpStatusCode.TemporaryRedirect,
+ "response",
+ "Redirecting response expected.");
+ Requires.Argument(response.Headers.Location != null, "response", "Redirect URL header expected.");
+ Requires.Argument(response.Content == null || response.Content is FormUrlEncodedContent, "response", "FormUrlEncodedContent expected");
+
+ var builder = new UriBuilder(response.Headers.Location);
+ if (response.Content != null) {
+ var content = response.Content.ReadAsStringAsync();
+ Assumes.True(content.IsCompleted); // cached in memory, so it should never complete asynchronously.
+ var formFields = HttpUtility.ParseQueryString(content.Result).ToDictionary();
+ MessagingUtilities.AppendQueryArgs(builder, formFields);
+ }
+
+ return builder.Uri;
+ }
+
/// <summary>
/// Collects a sequence of key=value pairs into a dictionary.
/// </summary>