Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Replaced status code number with constants #1924

Merged
merged 1 commit into from
Feb 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.WebUtilities;

namespace Microsoft.AspNet.Mvc
{
Expand All @@ -17,7 +18,7 @@ public class BadRequestObjectResult : ObjectResult
public BadRequestObjectResult(object error)
: base(error)
{
StatusCode = 400;
StatusCode = StatusCodes.Status400BadRequest;
}

/// <summary>
Expand All @@ -27,7 +28,7 @@ public BadRequestObjectResult(object error)
public BadRequestObjectResult([NotNull] ModelStateDictionary modelState)
: base(new SerializableError(modelState))
{
StatusCode = 400;
StatusCode = StatusCodes.Status400BadRequest;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.WebUtilities;

namespace Microsoft.AspNet.Mvc
{
/// <summary>
Expand All @@ -13,7 +15,7 @@ public class BadRequestResult : HttpStatusCodeResult
/// Creates a new <see cref="BadRequestResult"/> instance.
/// </summary>
public BadRequestResult()
: base(400)
: base(StatusCodes.Status400BadRequest)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.WebUtilities;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tratcher would you guys consider moving this to more common namespace? As is it kinda makes me sad 😢

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With or without moving it to a new assembly?

Suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Microsoft.aspnet.http ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shrug File a bug. HttpAbstractions needs a full organizational review anyways.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using Microsoft.Framework.DependencyInjection;

namespace Microsoft.AspNet.Mvc
Expand All @@ -30,7 +31,7 @@ public CreatedAtActionResult(string actionName,
ActionName = actionName;
ControllerName = controllerName;
RouteValues = TypeHelper.ObjectToDictionary(routeValues);
StatusCode = 201;
StatusCode = StatusCodes.Status201Created;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.DependencyInjection;

namespace Microsoft.AspNet.Mvc
Expand Down Expand Up @@ -38,7 +39,7 @@ public CreatedAtRouteResult(string routeName,
{
RouteName = routeName;
RouteValues = TypeHelper.ObjectToDictionary(routeValues);
StatusCode = 201;
StatusCode = StatusCodes.Status201Created;
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.AspNet.Mvc.Core/ActionResults/CreatedResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.AspNet.WebUtilities;

namespace Microsoft.AspNet.Mvc
{
Expand All @@ -22,7 +23,7 @@ public CreatedResult([NotNull] string location, object value)
: base(value)
{
Location = location;
StatusCode = 201;
StatusCode = StatusCodes.Status201Created;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.WebUtilities;

namespace Microsoft.AspNet.Mvc
{
/// <summary>
Expand All @@ -12,7 +14,7 @@ public class HttpNotFoundResult : HttpStatusCodeResult
/// <summary>
/// Creates a new <see cref="HttpNotFoundResult"/> instance.
/// </summary>
public HttpNotFoundResult() : base(404)
public HttpNotFoundResult() : base(StatusCodes.Status404NotFound)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.WebUtilities;

namespace Microsoft.AspNet.Mvc
{
public class NoContentResult : HttpStatusCodeResult
{
public NoContentResult()
: base(204)
: base(StatusCodes.Status204NoContent)
{
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.AspNet.Mvc.Core/ActionResults/ObjectResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.OptionsModel;
using Microsoft.Net.Http.Headers;
Expand Down Expand Up @@ -53,7 +54,7 @@ public override async Task ExecuteResultAsync(ActionContext context)
if (selectedFormatter == null)
{
// No formatter supports this.
context.HttpContext.Response.StatusCode = 406;
context.HttpContext.Response.StatusCode = StatusCodes.Status406NotAcceptable;
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.WebUtilities;

namespace Microsoft.AspNet.Mvc
{
/// <summary>
Expand All @@ -12,7 +14,7 @@ public class UnsupportedMediaTypeResult : HttpStatusCodeResult
/// <summary>
/// Creates a new instance of <see cref="UnsupportedMediaTypeResult"/>.
/// </summary>
public UnsupportedMediaTypeResult() : base(415)
public UnsupportedMediaTypeResult() : base(StatusCodes.Status415UnsupportedMediaType)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.WebUtilities;

namespace Microsoft.AspNet.Mvc
{
Expand Down Expand Up @@ -31,7 +32,7 @@ protected virtual bool HasAllowAnonymous([NotNull] AuthorizationContext context)

protected virtual void Fail([NotNull] AuthorizationContext context)
{
context.Result = new HttpStatusCodeResult(401);
context.Result = new HttpStatusCodeResult(StatusCodes.Status401Unauthorized);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Net.Http.Headers;

namespace Microsoft.AspNet.Mvc
Expand Down Expand Up @@ -44,7 +45,7 @@ public Task WriteAsync(OutputFormatterContext context)
{
var response = context.ActionContext.HttpContext.Response;
response.ContentLength = 0;
response.StatusCode = context.StatusCode ?? 204;
response.StatusCode = context.StatusCode ?? StatusCodes.Status204NoContent;
return Task.FromResult(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Net.Http.Headers;

namespace Microsoft.AspNet.Mvc
Expand Down Expand Up @@ -32,7 +33,7 @@ public IReadOnlyList<MediaTypeHeaderValue> GetSupportedContentTypes(Type declare
public Task WriteAsync(OutputFormatterContext context)
{
var response = context.ActionContext.HttpContext.Response;
response.StatusCode = 406;
response.StatusCode = StatusCodes.Status406NotAcceptable;
return Task.FromResult(true);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.AspNet.Mvc.Core/RequireHttpsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.AspNet.WebUtilities;

namespace Microsoft.AspNet.Mvc
{
Expand All @@ -25,7 +26,7 @@ protected virtual void HandleNonHttpsRequest(AuthorizationContext filterContext)
// body correctly.
if (!string.Equals(filterContext.HttpContext.Request.Method, "GET", StringComparison.OrdinalIgnoreCase))
{
filterContext.Result = new HttpStatusCodeResult(403);
filterContext.Result = new HttpStatusCodeResult(StatusCodes.Status403Forbidden);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;

namespace System.Web.Http
{
/// <summary>
/// An action result that returns a <see cref="System.Net.HttpStatusCode.BadRequest"/> response and performs
/// An action result that returns a <see cref="StatusCodes.Status400BadRequest"/> response and performs
/// content negotiation on an <see cref="HttpError"/> with a <see cref="HttpError.Message"/>.
/// </summary>
public class BadRequestErrorMessageResult : ObjectResult
Expand All @@ -29,7 +30,7 @@ public BadRequestErrorMessageResult([NotNull] string message)
/// <inheritdoc />
public override async Task ExecuteResultAsync(ActionContext context)
{
context.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
context.HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
await base.ExecuteResultAsync(context);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Net;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;

namespace System.Web.Http
{
/// <summary>
/// An action result that returns an empty <see cref="HttpStatusCode.Conflict"/> response.
/// An action result that returns an empty <see cref="StatusCodes.Status409Conflict"/> response.
/// </summary>
public class ConflictResult : HttpStatusCodeResult
{
/// <summary>
/// Initializes a new instance of the <see cref="ConflictResult"/> class.
/// </summary>
public ConflictResult()
: base((int)HttpStatusCode.Conflict)
: base(StatusCodes.Status409Conflict)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;

namespace System.Web.Http
{
/// <summary>
/// An action result that returns a <see cref="HttpStatusCode.InternalServerError"/> response and
/// An action result that returns a <see cref="StatusCodes.Status500InternalServerError"/> response and
/// performs content negotiation on an <see cref="HttpError"/> based on an <see cref="Exception"/>.
/// </summary>
public class ExceptionResult : ObjectResult
Expand Down Expand Up @@ -41,7 +41,7 @@ public ExceptionResult(Exception exception, bool includeErrorDetail)
/// <inheritdoc />
public override Task ExecuteResultAsync(ActionContext context)
{
context.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
context.HttpContext.Response.StatusCode = StatusCodes.Status500InternalServerError;
return base.ExecuteResultAsync(context);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Net;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;

namespace System.Web.Http
{
/// <summary>
/// An action result that returns an empty <see cref="HttpStatusCode.InternalServerError"/> response.
/// An action result that returns an empty <see cref="StatusCodes.Status500InternalServerError"/> response.
/// </summary>
public class InternalServerErrorResult : HttpStatusCodeResult
{
/// <summary>
/// Initializes a new instance of the <see cref="InternalServerErrorResult"/> class.
/// </summary>
public InternalServerErrorResult()
: base((int)HttpStatusCode.InternalServerError)
: base(StatusCodes.Status500InternalServerError)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.WebUtilities;

namespace System.Web.Http
{
/// <summary>
/// An action result that returns a <see cref="System.Net.HttpStatusCode.BadRequest"/> response and performs
/// An action result that returns a <see cref="StatusCodes.Status400BadRequest"/> response and performs
/// content negotiation on an <see cref="HttpError"/> based on a <see cref="ModelStateDictionary"/>.
/// </summary>
public class InvalidModelStateResult : ObjectResult
Expand Down Expand Up @@ -39,7 +39,7 @@ public InvalidModelStateResult([NotNull] ModelStateDictionary modelState, bool i
/// <inheritdoc />
public override async Task ExecuteResultAsync(ActionContext context)
{
context.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
context.HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
await base.ExecuteResultAsync(context);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Net;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;

namespace System.Web.Http
{
/// <summary>
/// An action result that returns an empty <see cref="HttpStatusCode.OK"/> response.
/// An action result that returns an empty <see cref="StatusCodes.Status200OK"/> response.
/// </summary>
public class OkResult : HttpStatusCodeResult
{
/// <summary>
/// Initializes a new instance of the <see cref="OkResult"/> class.
/// </summary>
public OkResult()
: base((int)HttpStatusCode.OK)
: base(StatusCodes.Status200OK)
{
}
}
Expand Down
Loading