Last active
August 29, 2015 14:16
-
-
Save fubar-coder/d8eb45356a0bfd0cd405 to your computer and use it in GitHub Desktop.
HTTP message handler with an active "AllowAutoRedirect"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net.Http; | |
namespace RestSharp.Portable.HttpClientImpl | |
{ | |
/// <summary> | |
/// Creates a HTTP message handler with an active "AllowAutoRedirect". | |
/// </summary> | |
public class FollowRedirectHttpClientFactory : DefaultHttpClientFactory | |
{ | |
/// <summary> | |
/// Create the message handler | |
/// </summary> | |
/// <param name="client"> | |
/// The REST client that wants to create the HTTP client | |
/// </param> | |
/// <param name="request"> | |
/// The REST request for which the HTTP client is created | |
/// </param> | |
/// <returns> | |
/// A new HttpMessageHandler object | |
/// </returns> | |
protected override HttpMessageHandler CreateMessageHandler(IRestClient client, IRestRequest request) | |
{ | |
HttpMessageHandler messageHandler = base.CreateMessageHandler(client, request); | |
var clientHandler = messageHandler as HttpClientHandler; | |
if (clientHandler != null && clientHandler.SupportsRedirectConfiguration) | |
{ | |
clientHandler.AllowAutoRedirect = true; | |
} | |
return messageHandler; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment