summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/CookieContainerExtensions.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2013-03-26 11:19:06 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2013-03-26 11:19:06 -0700
commit3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb (patch)
treec15816c3d7f6e74334553f2ff98605ce1c22c538 /src/DotNetOpenAuth.Test/CookieContainerExtensions.cs
parent5e9014f36b2d53b8e419918675df636540ea24e2 (diff)
parente6f7409f4caceb7bc2a5b4ddbcb1a4097af340f2 (diff)
downloadDotNetOpenAuth-3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb.zip
DotNetOpenAuth-3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb.tar.gz
DotNetOpenAuth-3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb.tar.bz2
Move to HttpClient throughout library.
Diffstat (limited to 'src/DotNetOpenAuth.Test/CookieContainerExtensions.cs')
-rw-r--r--src/DotNetOpenAuth.Test/CookieContainerExtensions.cs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.Test/CookieContainerExtensions.cs b/src/DotNetOpenAuth.Test/CookieContainerExtensions.cs
new file mode 100644
index 0000000..5a09d13
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/CookieContainerExtensions.cs
@@ -0,0 +1,38 @@
+//-----------------------------------------------------------------------
+// <copyright file="CookieContainerExtensions.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test {
+ using System;
+ using System.Collections.Generic;
+ using System.Net;
+ using System.Net.Http;
+
+ using Validation;
+
+ internal static class CookieContainerExtensions {
+ internal static void SetCookies(this CookieContainer container, HttpResponseMessage response, Uri requestUri = null) {
+ Requires.NotNull(container, "container");
+ Requires.NotNull(response, "response");
+
+ IEnumerable<string> cookieHeaders;
+ if (response.Headers.TryGetValues("Set-Cookie", out cookieHeaders)) {
+ foreach (string cookie in cookieHeaders) {
+ container.SetCookies(requestUri ?? response.RequestMessage.RequestUri, cookie);
+ }
+ }
+ }
+
+ internal static void ApplyCookies(this CookieContainer container, HttpRequestMessage request) {
+ Requires.NotNull(container, "container");
+ Requires.NotNull(request, "request");
+
+ string cookieHeader = container.GetCookieHeader(request.RequestUri);
+ if (!string.IsNullOrEmpty(cookieHeader)) {
+ request.Headers.TryAddWithoutValidation("Cookie", cookieHeader);
+ }
+ }
+ }
+} \ No newline at end of file