forked from DotNetOpenAuth/DotNetOpenAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCookieDelegatingHandler.cs
31 lines (27 loc) · 1.1 KB
/
CookieDelegatingHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//-----------------------------------------------------------------------
// <copyright file="CookieDelegatingHandler.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Test {
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
internal class CookieDelegatingHandler : DelegatingHandler {
internal CookieDelegatingHandler(HttpMessageHandler innerHandler, CookieContainer cookieContainer = null)
: base(innerHandler) {
this.Container = cookieContainer ?? new CookieContainer();
}
public CookieContainer Container { get; set; }
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
this.Container.ApplyCookies(request);
var response = await base.SendAsync(request, cancellationToken);
this.Container.SetCookies(response);
return response;
}
}
}