Skip to content

Instantly share code, notes, and snippets.

@fubar-coder
Last active August 29, 2015 14:16
Show Gist options
  • Save fubar-coder/d8eb45356a0bfd0cd405 to your computer and use it in GitHub Desktop.
Save fubar-coder/d8eb45356a0bfd0cd405 to your computer and use it in GitHub Desktop.
HTTP message handler with an active "AllowAutoRedirect"
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