summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OpenId/Yadis/DiscoveryResult.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.OpenId/Yadis/DiscoveryResult.cs')
-rw-r--r--src/DotNetOpenAuth.OpenId/Yadis/DiscoveryResult.cs63
1 files changed, 39 insertions, 24 deletions
diff --git a/src/DotNetOpenAuth.OpenId/Yadis/DiscoveryResult.cs b/src/DotNetOpenAuth.OpenId/Yadis/DiscoveryResult.cs
index 06c6fc7..64f7b66 100644
--- a/src/DotNetOpenAuth.OpenId/Yadis/DiscoveryResult.cs
+++ b/src/DotNetOpenAuth.OpenId/Yadis/DiscoveryResult.cs
@@ -7,10 +7,15 @@
namespace DotNetOpenAuth.Yadis {
using System;
using System.IO;
+ using System.Net;
+ using System.Net.Http;
+ using System.Net.Http.Headers;
using System.Net.Mime;
+ using System.Threading.Tasks;
using System.Web.UI.HtmlControls;
using System.Xml;
using DotNetOpenAuth.Messaging;
+ using Validation;
/// <summary>
/// Contains the result of YADIS discovery.
@@ -20,7 +25,7 @@ namespace DotNetOpenAuth.Yadis {
/// The original web response, backed up here if the final web response is the preferred response to use
/// in case it turns out to not work out.
/// </summary>
- private CachedDirectWebResponse htmlFallback;
+ private HttpResponseMessage htmlFallback;
/// <summary>
/// Initializes a new instance of the <see cref="DiscoveryResult"/> class.
@@ -28,22 +33,7 @@ namespace DotNetOpenAuth.Yadis {
/// <param name="requestUri">The user-supplied identifier.</param>
/// <param name="initialResponse">The initial response.</param>
/// <param name="finalResponse">The final response.</param>
- public DiscoveryResult(Uri requestUri, CachedDirectWebResponse initialResponse, CachedDirectWebResponse finalResponse) {
- this.RequestUri = requestUri;
- this.NormalizedUri = initialResponse.FinalUri;
- if (finalResponse == null || finalResponse.Status != System.Net.HttpStatusCode.OK) {
- this.ApplyHtmlResponse(initialResponse);
- } else {
- this.ContentType = finalResponse.ContentType;
- this.ResponseText = finalResponse.GetResponseString();
- this.IsXrds = true;
- if (initialResponse != finalResponse) {
- this.YadisLocation = finalResponse.RequestUri;
- }
-
- // Back up the initial HTML response in case the XRDS is not useful.
- this.htmlFallback = initialResponse;
- }
+ private DiscoveryResult() {
}
/// <summary>
@@ -68,7 +58,7 @@ namespace DotNetOpenAuth.Yadis {
/// <summary>
/// Gets the Content-Type associated with the <see cref="ResponseText"/>.
/// </summary>
- public ContentType ContentType { get; private set; }
+ public MediaTypeHeaderValue ContentType { get; private set; }
/// <summary>
/// Gets the text in the final response.
@@ -83,12 +73,35 @@ namespace DotNetOpenAuth.Yadis {
/// </summary>
public bool IsXrds { get; private set; }
+ internal static async Task<DiscoveryResult> CreateAsync(
+ Uri requestUri, HttpResponseMessage initialResponse, HttpResponseMessage finalResponse) {
+
+ var result = new DiscoveryResult();
+ result.RequestUri = requestUri;
+ result.NormalizedUri = initialResponse.RequestMessage.RequestUri;
+ if (finalResponse == null || finalResponse.StatusCode != HttpStatusCode.OK) {
+ await result.ApplyHtmlResponseAsync(initialResponse);
+ } else {
+ result.ContentType = finalResponse.Content.Headers.ContentType;
+ result.ResponseText = await finalResponse.Content.ReadAsStringAsync();
+ result.IsXrds = true;
+ if (initialResponse != finalResponse) {
+ result.YadisLocation = finalResponse.RequestMessage.RequestUri;
+ }
+
+ // Back up the initial HTML response in case the XRDS is not useful.
+ result.htmlFallback = initialResponse;
+ }
+
+ return result;
+ }
+
/// <summary>
/// Reverts to the HTML response after the XRDS response didn't work out.
/// </summary>
- internal void TryRevertToHtmlResponse() {
+ internal async Task TryRevertToHtmlResponseAsync() {
if (this.htmlFallback != null) {
- this.ApplyHtmlResponse(this.htmlFallback);
+ await this.ApplyHtmlResponseAsync(this.htmlFallback);
this.htmlFallback = null;
}
}
@@ -96,10 +109,12 @@ namespace DotNetOpenAuth.Yadis {
/// <summary>
/// Applies the HTML response to the object.
/// </summary>
- /// <param name="initialResponse">The initial response.</param>
- private void ApplyHtmlResponse(CachedDirectWebResponse initialResponse) {
- this.ContentType = initialResponse.ContentType;
- this.ResponseText = initialResponse.GetResponseString();
+ /// <param name="response">The initial response.</param>
+ private async Task ApplyHtmlResponseAsync(HttpResponseMessage response) {
+ Requires.NotNull(response, "response");
+
+ this.ContentType = response.Content.Headers.ContentType;
+ this.ResponseText = await response.Content.ReadAsStringAsync();
this.IsXrds = this.ContentType != null && this.ContentType.MediaType == ContentTypes.Xrds;
}
}