summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Core
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Core')
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/Bindings/StandardExpirationBindingElement.cs7
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/Bindings/StandardReplayProtectionBindingElement.cs7
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/Channel.cs19
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs78
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/MultipartContentMember.cs27
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/ProtocolFaultResponseException.cs5
-rw-r--r--src/DotNetOpenAuth.Core/Util.cs12
7 files changed, 134 insertions, 21 deletions
diff --git a/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardExpirationBindingElement.cs b/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardExpirationBindingElement.cs
index c706e42..f19d4bd 100644
--- a/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardExpirationBindingElement.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardExpirationBindingElement.cs
@@ -15,7 +15,14 @@ namespace DotNetOpenAuth.Messaging.Bindings {
/// implementing the <see cref="IExpiringProtocolMessage"/> interface.
/// </summary>
internal class StandardExpirationBindingElement : IChannelBindingElement {
+ /// <summary>
+ /// A reusable pre-completed task that may be returned multiple times to reduce GC pressure.
+ /// </summary>
private static readonly Task<MessageProtections?> NullTask = Task.FromResult<MessageProtections?>(null);
+
+ /// <summary>
+ /// A reusable pre-completed task that may be returned multiple times to reduce GC pressure.
+ /// </summary>
private static readonly Task<MessageProtections?> CompletedExpirationTask = Task.FromResult<MessageProtections?>(MessageProtections.Expiration);
/// <summary>
diff --git a/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardReplayProtectionBindingElement.cs b/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardReplayProtectionBindingElement.cs
index 6c062d6..65c7882 100644
--- a/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardReplayProtectionBindingElement.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardReplayProtectionBindingElement.cs
@@ -15,7 +15,14 @@ namespace DotNetOpenAuth.Messaging.Bindings {
/// A binding element that checks/verifies a nonce message part.
/// </summary>
internal class StandardReplayProtectionBindingElement : IChannelBindingElement {
+ /// <summary>
+ /// A reusable, precompleted task that can be returned many times to reduce GC pressure.
+ /// </summary>
private static readonly Task<MessageProtections?> NullTask = Task.FromResult<MessageProtections?>(null);
+
+ /// <summary>
+ /// A reusable, precompleted task that can be returned many times to reduce GC pressure.
+ /// </summary>
private static readonly Task<MessageProtections?> CompletedReplayProtectionTask = Task.FromResult<MessageProtections?>(MessageProtections.ReplayProtection);
/// <summary>
diff --git a/src/DotNetOpenAuth.Core/Messaging/Channel.cs b/src/DotNetOpenAuth.Core/Messaging/Channel.cs
index 6aaf8ea..a134180 100644
--- a/src/DotNetOpenAuth.Core/Messaging/Channel.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/Channel.cs
@@ -330,11 +330,14 @@ namespace DotNetOpenAuth.Messaging {
/// <summary>
/// Gets the protocol message embedded in the given HTTP request, if present.
/// </summary>
- /// <returns>The deserialized message, if one is found. Null otherwise.</returns>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>
+ /// The deserialized message, if one is found. Null otherwise.
+ /// </returns>
+ /// <exception cref="InvalidOperationException">Thrown when <see cref="HttpContext.Current" /> is null.</exception>
/// <remarks>
/// Requires an HttpContext.Current context.
/// </remarks>
- /// <exception cref="InvalidOperationException">Thrown when <see cref="HttpContext.Current"/> is null.</exception>
public Task<IDirectedProtocolMessage> ReadFromRequestAsync(CancellationToken cancellationToken) {
return this.ReadFromRequestAsync(this.GetRequestFromContext(), cancellationToken);
}
@@ -716,7 +719,15 @@ namespace DotNetOpenAuth.Messaging {
}
}
+ /// <summary>
+ /// Provides derived-types the opportunity to wrap an <see cref="HttpMessageHandler"/> with another one.
+ /// </summary>
+ /// <param name="innerHandler">The inner handler received from <see cref="IHostFactories"/></param>
+ /// <returns>The handler to use in <see cref="HttpClient"/> instances.</returns>
protected virtual HttpMessageHandler WrapMessageHandler(HttpMessageHandler innerHandler) {
+ //TODO: make sure that everyone calls this to wrap their handlers rather than using the one directly returned
+ //from IHostFactories.
+
// No wrapping by default.
return innerHandler;
}
@@ -971,7 +982,7 @@ namespace DotNetOpenAuth.Messaging {
/// <returns>
/// A task that completes with the asynchronous operation.
/// </returns>
- /// <exception cref="UnprotectedMessageException"></exception>
+ /// <exception cref="UnprotectedMessageException">Thrown if the message does not have the minimal required protections applied.</exception>
/// <remarks>
/// This method should NOT be called by derived types
/// except when sending ONE WAY request messages.
@@ -1145,7 +1156,7 @@ namespace DotNetOpenAuth.Messaging {
/// <returns>
/// A task that completes with the asynchronous operation.
/// </returns>
- /// <exception cref="UnprotectedMessageException"></exception>
+ /// <exception cref="UnprotectedMessageException">Thrown if the message does not have the minimal required protections applied.</exception>
/// <exception cref="ProtocolException">Thrown when the message is somehow invalid.
/// This can be due to tampering, replay attack or expiration, among other things.</exception>
protected virtual async Task ProcessIncomingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) {
diff --git a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
index 5286f84..b84bd48 100644
--- a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
@@ -380,11 +380,25 @@ namespace DotNetOpenAuth.Messaging {
return GetPublicFacingUrl(request, request.ServerVariables);
}
+ /// <summary>
+ /// Wraps a response message as an MVC <see cref="ActionResult"/> so it can be conveniently returned from an MVC controller's action method.
+ /// </summary>
+ /// <param name="response">The response message.</param>
+ /// <returns>An <see cref="ActionResult"/> instance.</returns>
public static ActionResult AsActionResult(this HttpResponseMessage response) {
Requires.NotNull(response, "response");
return new HttpResponseMessageActionResult(response);
}
+ /// <summary>
+ /// Sends a response message to the HTTP client.
+ /// </summary>
+ /// <param name="response">The response message.</param>
+ /// <param name="responseContext">The response context to send the response with.</param>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>
+ /// A task that completes with the asynchronous operation.
+ /// </returns>
public static async Task SendAsync(this HttpResponseMessage response, HttpResponseBase responseContext = null, CancellationToken cancellationToken = default(CancellationToken)) {
Requires.NotNull(response, "response");
if (responseContext == null) {
@@ -405,26 +419,41 @@ namespace DotNetOpenAuth.Messaging {
}
}
- public static void Send(this HttpResponseMessage response, HttpContextBase context = null) {
- Requires.NotNull(response, "response");
- if (context == null) {
- ErrorUtilities.VerifyHttpContext();
- context = new HttpContextWrapper(HttpContext.Current);
- }
-
- SendAsync(response, context.Response).GetAwaiter().GetResult();
+ /// <summary>
+ /// Sends a response message to the HTTP client.
+ /// </summary>
+ /// <param name="response">The response message.</param>
+ /// <param name="responseContext">The response context to send the response with.</param>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ public static void Send(this HttpResponseMessage response, HttpResponseBase responseContext = null, CancellationToken cancellationToken = default(CancellationToken)) {
+ SendAsync(response, responseContext, cancellationToken).GetAwaiter().GetResult();
}
+ /// <summary>
+ /// Disposes a value if it is not null.
+ /// </summary>
+ /// <param name="disposable">The disposable value.</param>
internal static void DisposeIfNotNull(this IDisposable disposable) {
if (disposable != null) {
disposable.Dispose();
}
}
- internal static HttpRequestMessage Clone(this HttpRequestMessage original, Uri newRequestUri = null) {
+ /// <summary>
+ /// Clones the specified <see cref="HttpRequestMessage"/> so it can be re-sent.
+ /// </summary>
+ /// <param name="original">The original message.</param>
+ /// <returns>The cloned message</returns>
+ /// <remarks>
+ /// This is useful when an HTTP request fails, and after a little tweaking should be resent.
+ /// Since <see cref="HttpRequestMessage"/> remembers it was already sent, it will not permit being
+ /// sent a second time. This method clones the message so its contents are identical but allows
+ /// re-sending.
+ /// </remarks>
+ internal static HttpRequestMessage Clone(this HttpRequestMessage original) {
Requires.NotNull(original, "original");
- var clone = new HttpRequestMessage(original.Method, newRequestUri ?? original.RequestUri);
+ var clone = new HttpRequestMessage(original.Method, original.RequestUri);
clone.Content = original.Content;
foreach (var header in original.Headers) {
clone.Headers.Add(header.Key, header.Value);
@@ -511,9 +540,10 @@ namespace DotNetOpenAuth.Messaging {
/// <summary>
/// Assembles the content of the HTTP Authorization or WWW-Authenticate header.
/// </summary>
- /// <param name="scheme">The scheme.</param>
/// <param name="fields">The fields to include.</param>
- /// <returns>A value prepared for an HTTP header.</returns>
+ /// <returns>
+ /// A value prepared for an HTTP header.
+ /// </returns>
internal static string AssembleAuthorizationHeader(IEnumerable<KeyValuePair<string, string>> fields) {
Requires.NotNull(fields, "fields");
@@ -639,6 +669,8 @@ namespace DotNetOpenAuth.Messaging {
/// Adds a Set-Cookie HTTP header for the specified cookie.
/// WARNING: support for cookie properties is currently VERY LIMITED.
/// </summary>
+ /// <param name="headers">The headers.</param>
+ /// <param name="cookie">The cookie.</param>
internal static void SetCookie(this HttpResponseHeaders headers, Cookie cookie) {
Requires.NotNull(headers, "headers");
Requires.NotNull(cookie, "cookie");
@@ -1531,6 +1563,12 @@ namespace DotNetOpenAuth.Messaging {
}
}
+ /// <summary>
+ /// Gets the URI that contains the entire payload that would be sent by the browser for the specified redirect-based request message.
+ /// </summary>
+ /// <param name="response">The redirecting response message.</param>
+ /// <returns>The absolute URI that could be retrieved to send the same message the browser would.</returns>
+ /// <exception cref="System.NotSupportedException">Thrown if the message is not a redirect message.</exception>
internal static Uri GetDirectUriRequest(this HttpResponseMessage response) {
Requires.NotNull(response, "response");
Requires.Argument(
@@ -2009,16 +2047,30 @@ namespace DotNetOpenAuth.Messaging {
#endregion
}
+ /// <summary>
+ /// An MVC <see cref="ActionResult"/> that wraps an <see cref="HttpResponseMessage"/>
+ /// </summary>
private class HttpResponseMessageActionResult : ActionResult {
+ /// <summary>
+ /// The wrapped response.
+ /// </summary>
private readonly HttpResponseMessage response;
+ /// <summary>
+ /// Initializes a new instance of the <see cref="HttpResponseMessageActionResult"/> class.
+ /// </summary>
+ /// <param name="response">The response.</param>
internal HttpResponseMessageActionResult(HttpResponseMessage response) {
Requires.NotNull(response, "response");
this.response = response;
}
+ /// <summary>
+ /// Enables processing of the result of an action method by a custom type that inherits from the <see cref="T:System.Web.Mvc.ActionResult" /> class.
+ /// </summary>
+ /// <param name="context">The context in which the result is executed. The context information includes the controller, HTTP content, request context, and route data.</param>
public override void ExecuteResult(ControllerContext context) {
- this.response.Send(context.HttpContext);
+ this.response.Send(context.HttpContext.Response);
}
}
}
diff --git a/src/DotNetOpenAuth.Core/Messaging/MultipartContentMember.cs b/src/DotNetOpenAuth.Core/Messaging/MultipartContentMember.cs
index cc9d806..fd5bfb5 100644
--- a/src/DotNetOpenAuth.Core/Messaging/MultipartContentMember.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/MultipartContentMember.cs
@@ -12,7 +12,16 @@ namespace DotNetOpenAuth.Messaging {
using System.Text;
using System.Threading.Tasks;
+ /// <summary>
+ /// Describes a part from a multi-part POST.
+ /// </summary>
public struct MultipartContentMember {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="MultipartContentMember"/> struct.
+ /// </summary>
+ /// <param name="content">The content.</param>
+ /// <param name="name">The name of this part as it may come from an HTML form.</param>
+ /// <param name="fileName">Name of the file.</param>
public MultipartContentMember(HttpContent content, string name = null, string fileName = null)
: this() {
this.Content = content;
@@ -20,10 +29,28 @@ namespace DotNetOpenAuth.Messaging {
this.FileName = fileName;
}
+ /// <summary>
+ /// Gets or sets the content.
+ /// </summary>
+ /// <value>
+ /// The content.
+ /// </value>
public HttpContent Content { get; set; }
+ /// <summary>
+ /// Gets or sets the HTML form name.
+ /// </summary>
+ /// <value>
+ /// The name.
+ /// </value>
public string Name { get; set; }
+ /// <summary>
+ /// Gets or sets the name of the file.
+ /// </summary>
+ /// <value>
+ /// The name of the file.
+ /// </value>
public string FileName { get; set; }
}
}
diff --git a/src/DotNetOpenAuth.Core/Messaging/ProtocolFaultResponseException.cs b/src/DotNetOpenAuth.Core/Messaging/ProtocolFaultResponseException.cs
index 9460417..b5cab3b 100644
--- a/src/DotNetOpenAuth.Core/Messaging/ProtocolFaultResponseException.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/ProtocolFaultResponseException.cs
@@ -64,7 +64,10 @@ namespace DotNetOpenAuth.Messaging {
/// <summary>
/// Creates the HTTP response to forward to the client to report the error.
/// </summary>
- /// <returns>The HTTP response.</returns>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>
+ /// The HTTP response.
+ /// </returns>
public Task<HttpResponseMessage> CreateErrorResponseAsync(CancellationToken cancellationToken) {
return this.channel.PrepareResponseAsync(this.ErrorResponseMessage, cancellationToken);
}
diff --git a/src/DotNetOpenAuth.Core/Util.cs b/src/DotNetOpenAuth.Core/Util.cs
index ebbaaa4..00d033f 100644
--- a/src/DotNetOpenAuth.Core/Util.cs
+++ b/src/DotNetOpenAuth.Core/Util.cs
@@ -29,6 +29,9 @@ namespace DotNetOpenAuth {
/// </summary>
internal const string DefaultNamespace = "DotNetOpenAuth";
+ /// <summary>
+ /// A lazily-assembled string that describes the version of the library.
+ /// </summary>
private static readonly Lazy<string> libraryVersionLazy = new Lazy<string>(delegate {
var assembly = Assembly.GetExecutingAssembly();
string assemblyFullName = assembly.FullName;
@@ -40,16 +43,19 @@ namespace DotNetOpenAuth {
});
/// <summary>
- /// The web.config file-specified provider of web resource URLs.
+ /// A lazily-assembled string that describes the version of the library.
/// </summary>
- private static IEmbeddedResourceRetrieval embeddedResourceRetrieval = MessagingElement.Configuration.EmbeddedResourceRetrievalProvider.CreateInstance(null, false, null);
-
private static readonly Lazy<ProductInfoHeaderValue> libraryVersionHeaderLazy = new Lazy<ProductInfoHeaderValue>(delegate {
var assemblyName = Assembly.GetExecutingAssembly().GetName();
return new ProductInfoHeaderValue(assemblyName.Name, AssemblyFileVersion);
});
/// <summary>
+ /// The web.config file-specified provider of web resource URLs.
+ /// </summary>
+ private static IEmbeddedResourceRetrieval embeddedResourceRetrieval = MessagingElement.Configuration.EmbeddedResourceRetrievalProvider.CreateInstance(null, false, null);
+
+ /// <summary>
/// Gets a human-readable description of the library name and version, including
/// whether the build is an official or private one.
/// </summary>