//-----------------------------------------------------------------------
//
// Copyright (c) Andrew Arnott. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenId {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Cache;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
///
/// Creates default instances of required dependencies.
///
public class DefaultOpenIdHostFactories : IHostFactories {
///
/// Initializes a new instance of a concrete derivation of
/// to be used for outbound HTTP traffic.
///
/// An instance of .
///
/// An instance of is recommended where available;
/// otherwise an instance of is recommended.
///
public virtual HttpMessageHandler CreateHttpMessageHandler() {
var handler = new UntrustedWebRequestHandler();
((WebRequestHandler)handler.InnerHandler).CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
return handler;
}
///
/// Initializes a new instance of the class
/// to be used for outbound HTTP traffic.
///
/// The handler to pass to the constructor.
/// May be null to use the default that would be provided by .
///
/// An instance of .
///
public HttpClient CreateHttpClient(HttpMessageHandler handler) {
handler = handler ?? this.CreateHttpMessageHandler();
var untrustedHandler = handler as UntrustedWebRequestHandler;
HttpClient client;
if (untrustedHandler != null) {
client = untrustedHandler.CreateClient();
} else {
client = new HttpClient(handler);
}
client.DefaultRequestHeaders.UserAgent.Add(Util.LibraryVersionHeader);
return client;
}
}
}