// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics.Contracts;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace System.Web.Http.Results
{
///
/// Represents an action result that returns an empty response.
///
public class InternalServerErrorResult : IHttpActionResult
{
private readonly StatusCodeResult.IDependencyProvider _dependencies;
/// Initializes a new instance of the class.
/// The request message which led to this result.
public InternalServerErrorResult(HttpRequestMessage request)
: this(new StatusCodeResult.DirectDependencyProvider(request))
{
}
/// Initializes a new instance of the class.
/// The controller from which to obtain the dependencies needed for execution.
public InternalServerErrorResult(ApiController controller)
: this(new StatusCodeResult.ApiControllerDependencyProvider(controller))
{
}
private InternalServerErrorResult(StatusCodeResult.IDependencyProvider dependencies)
{
Contract.Assert(dependencies != null);
_dependencies = dependencies;
}
/// Gets the request message which led to this result.
public HttpRequestMessage Request
{
get { return _dependencies.Request; }
}
///
public virtual Task ExecuteAsync(CancellationToken cancellationToken)
{
return Task.FromResult(StatusCodeResult.Execute(HttpStatusCode.InternalServerError,
_dependencies.Request));
}
}
}