diff options
Diffstat (limited to 'src/DotNetOpenAuth.Core')
-rw-r--r-- | src/DotNetOpenAuth.Core/Messaging/Bindings/StandardExpirationBindingElement.cs | 2 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Core/Messaging/Channel.cs | 2 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs | 2 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Core/Reporting.cs | 44 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Core/Util.cs | 32 |
5 files changed, 50 insertions, 32 deletions
diff --git a/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardExpirationBindingElement.cs b/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardExpirationBindingElement.cs index ace4cf5..3cb4500 100644 --- a/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardExpirationBindingElement.cs +++ b/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardExpirationBindingElement.cs @@ -104,7 +104,7 @@ namespace DotNetOpenAuth.Messaging.Bindings { return CompletedExpirationTask; } - return null; + return NullTask; } #endregion diff --git a/src/DotNetOpenAuth.Core/Messaging/Channel.cs b/src/DotNetOpenAuth.Core/Messaging/Channel.cs index 4d35c90..9d55e78 100644 --- a/src/DotNetOpenAuth.Core/Messaging/Channel.cs +++ b/src/DotNetOpenAuth.Core/Messaging/Channel.cs @@ -813,7 +813,7 @@ namespace DotNetOpenAuth.Messaging { }; response.Headers.Location = builder.Uri; - response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html; charset=utf-8"); + response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html") { CharSet = "utf-8" }; return response; } diff --git a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs index 9aee0e3..4f4eb66 100644 --- a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs +++ b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs @@ -1978,7 +1978,7 @@ namespace DotNetOpenAuth.Messaging { public override void ExecuteResult(ControllerContext context) { context.HttpContext.Response.StatusCode = (int)this.response.StatusCode; - context.HttpContext.Response.Status = this.response.ReasonPhrase; + context.HttpContext.Response.StatusDescription = this.response.ReasonPhrase; foreach (var header in this.response.Headers) { foreach (var value in header.Value) { context.HttpContext.Response.AddHeader(header.Key, value); diff --git a/src/DotNetOpenAuth.Core/Reporting.cs b/src/DotNetOpenAuth.Core/Reporting.cs index 46b3d95..e291851 100644 --- a/src/DotNetOpenAuth.Core/Reporting.cs +++ b/src/DotNetOpenAuth.Core/Reporting.cs @@ -74,11 +74,6 @@ namespace DotNetOpenAuth { private static Uri wellKnownPostLocation = new Uri("https://reports.dotnetopenauth.net/ReportingPost.ashx"); /// <summary> - /// The outgoing HTTP request handler to use for publishing reports. - /// </summary> - private static HttpClient webRequestHandler; - - /// <summary> /// A few HTTP request hosts and paths we've seen. /// </summary> private static PersistentHashSet observedRequests; @@ -349,10 +344,6 @@ namespace DotNetOpenAuth { file = GetIsolatedStorage(); reportOriginIdentity = GetOrCreateOriginIdentity(); - var channel = new HttpClientHandler(); - channel.AllowAutoRedirect = false; - webRequestHandler = new HttpClient(channel); - webRequestHandler.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(new ProductHeaderValue(Util.LibraryVersion))); observations.Add(observedRequests = new PersistentHashSet(file, "requests.txt", 3)); observations.Add(observedCultures = new PersistentHashSet(file, "cultures.txt", 20)); observations.Add(observedFeatures = new PersistentHashSet(file, "features.txt", int.MaxValue)); @@ -377,6 +368,17 @@ namespace DotNetOpenAuth { } /// <summary> + /// Creates an HTTP client that can be used for outbound HTTP requests. + /// </summary> + private static HttpClient CreateHttpClient() { + var channel = new HttpClientHandler(); + channel.AllowAutoRedirect = false; + var webRequestHandler = new HttpClient(channel); + webRequestHandler.DefaultRequestHeaders.UserAgent.Add(Util.LibraryVersionHeader); + return webRequestHandler; + } + + /// <summary> /// Assembles a report for submission. /// </summary> /// <returns>A stream that contains the report.</returns> @@ -437,17 +439,19 @@ namespace DotNetOpenAuth { Stream report = GetReport(); var content = new StreamContent(report); content.Headers.ContentType = new MediaTypeHeaderValue("text/dnoa-report1"); - using (var response = await webRequestHandler.PostAsync(wellKnownPostLocation, content)) { - Logger.Library.Info("Statistical report submitted successfully."); - - // The response stream may contain a message for the webmaster. - // Since as part of the report we submit the library version number, - // the report receiving service may have alerts such as: - // "You're using an obsolete version with exploitable security vulnerabilities." - using (var responseReader = new StreamReader(await response.Content.ReadAsStreamAsync())) { - string line = await responseReader.ReadLineAsync(); - if (line != null) { - DemuxLogMessage(line); + using (var webRequestHandler = CreateHttpClient()) { + using (var response = await webRequestHandler.PostAsync(wellKnownPostLocation, content)) { + Logger.Library.Info("Statistical report submitted successfully."); + + // The response stream may contain a message for the webmaster. + // Since as part of the report we submit the library version number, + // the report receiving service may have alerts such as: + // "You're using an obsolete version with exploitable security vulnerabilities." + using (var responseReader = new StreamReader(await response.Content.ReadAsStreamAsync())) { + string line = await responseReader.ReadLineAsync(); + if (line != null) { + DemuxLogMessage(line); + } } } } diff --git a/src/DotNetOpenAuth.Core/Util.cs b/src/DotNetOpenAuth.Core/Util.cs index 279b7d3..ff91df1 100644 --- a/src/DotNetOpenAuth.Core/Util.cs +++ b/src/DotNetOpenAuth.Core/Util.cs @@ -8,11 +8,11 @@ namespace DotNetOpenAuth { using System.Collections.Generic; using System.Globalization; using System.Net; + using System.Net.Http.Headers; using System.Reflection; using System.Text; using System.Web; using System.Web.UI; - using DotNetOpenAuth.Configuration; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Reflection; @@ -32,20 +32,34 @@ namespace DotNetOpenAuth { /// </summary> private static IEmbeddedResourceRetrieval embeddedResourceRetrieval = MessagingElement.Configuration.EmbeddedResourceRetrievalProvider.CreateInstance(null, false, null); + private static readonly Lazy<string> libraryVersionLazy = new Lazy<string>(delegate { + var assembly = Assembly.GetExecutingAssembly(); + string assemblyFullName = assembly.FullName; + bool official = assemblyFullName.Contains("PublicKeyToken=2780ccd10d57b246"); + assemblyFullName = assemblyFullName.Replace(assembly.GetName().Version.ToString(), AssemblyFileVersion); + + // We use InvariantCulture since this is used for logging. + return string.Format(CultureInfo.InvariantCulture, "{0} ({1})", assemblyFullName, official ? "official" : "private"); + }); + + private static readonly Lazy<ProductInfoHeaderValue> libraryVersionHeaderLazy = new Lazy<ProductInfoHeaderValue>(delegate { + var assemblyName = Assembly.GetExecutingAssembly().GetName(); + return new ProductInfoHeaderValue(assemblyName.Name, AssemblyFileVersion); + }); + /// <summary> /// Gets a human-readable description of the library name and version, including /// whether the build is an official or private one. /// </summary> internal static string LibraryVersion { - get { - var assembly = Assembly.GetExecutingAssembly(); - string assemblyFullName = assembly.FullName; - bool official = assemblyFullName.Contains("PublicKeyToken=2780ccd10d57b246"); - assemblyFullName = assemblyFullName.Replace(assembly.GetName().Version.ToString(), AssemblyFileVersion); + get { return libraryVersionLazy.Value; } + } - // We use InvariantCulture since this is used for logging. - return string.Format(CultureInfo.InvariantCulture, "{0} ({1})", assemblyFullName, official ? "official" : "private"); - } + /// <summary> + /// Gets an HTTP header that can be included in outbound requests. + /// </summary> + internal static ProductInfoHeaderValue LibraryVersionHeader { + get { return libraryVersionHeaderLazy.Value; } } /// <summary> |