Api-Review - put uri complexity in CreatedResult

This commit is contained in:
Ryan Nowak 2015-09-20 19:11:37 -07:00
parent 42017faa21
commit ccb5ead450
2 changed files with 26 additions and 9 deletions

View File

@ -29,6 +29,27 @@ namespace Microsoft.AspNet.Mvc
StatusCode = StatusCodes.Status201Created; StatusCode = StatusCodes.Status201Created;
} }
/// <summary>
/// Initializes a new instance of the <see cref="CreatedResult"/> class with the values
/// provided.
/// </summary>
/// <param name="location">The location at which the content has been created.</param>
/// <param name="value">The value to format in the entity body.</param>
public CreatedResult([NotNull] Uri location, object value)
: base(value)
{
if (location.IsAbsoluteUri)
{
Location = location.AbsoluteUri;
}
else
{
Location = location.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped);
}
StatusCode = StatusCodes.Status201Created;
}
/// <summary> /// <summary>
/// Gets or sets the location at which the content has been created. /// Gets or sets the location at which the content has been created.
/// </summary> /// </summary>

View File

@ -941,17 +941,13 @@ namespace Microsoft.AspNet.Mvc
[NonAction] [NonAction]
public virtual CreatedResult Created([NotNull] Uri uri, object value) public virtual CreatedResult Created([NotNull] Uri uri, object value)
{ {
string location; var disposableValue = value as IDisposable;
if (uri.IsAbsoluteUri) if (disposableValue != null)
{ {
location = uri.AbsoluteUri; Response.RegisterForDispose(disposableValue);
} }
else
{ return new CreatedResult(uri, value);
location = uri.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped);
}
return Created(location, value);
} }
/// <summary> /// <summary>