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

Adding HTTP method constants #712

Merged
merged 11 commits into from
Sep 27, 2016
24 changes: 24 additions & 0 deletions src/Microsoft.AspNetCore.Http.Abstractions/HttpMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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;

namespace Microsoft.AspNetCore.Http
{
public static class HttpMethods
Copy link
Member

Choose a reason for hiding this comment

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

Should this be singular?
HttpMethod.Get
HttpMethod.IsGet(string)
HttpMethod.Equals(string, string)

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. This is similar to a non-flag enum.

{
public const string Connect = "CONNECT";
public const string Delete = "DELETE";
public const string Get = "GET";
public const string Options = "OPTIONS";
public const string Patch = "PATCH";
public const string Post = "POST";
public const string Put = "PUT";
public const string Trace = "TRACE";
Copy link
Member

Choose a reason for hiding this comment

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

I'm for keeping these const. ReferenceEquals still works across assembly boundaries. Just don't mess up 😛 .

Copy link
Member

Choose a reason for hiding this comment

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

static readonly

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, constants would be nicer (e.g they could be used for attribute values) 👍


public static bool Equals(string firstMethod, string secondMethod)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this? Where are we going to use it?

{
return StringComparer.OrdinalIgnoreCase.Equals(firstMethod, secondMethod);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

we should still have the Equals(string, string) method

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Http.Features;
using Xunit;
using Microsoft.AspNetCore.Http;
Copy link
Member

Choose a reason for hiding this comment

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

Sort usings


namespace Microsoft.AspNetCore.Owin
{
Expand All @@ -25,15 +26,15 @@ public void OwinHttpEnvironmentCanBeCreated()
{
var env = new Dictionary<string, object>
{
{ "owin.RequestMethod", "POST" },
{ "owin.RequestMethod", HttpMethods.Post },
{ "owin.RequestPath", "/path" },
{ "owin.RequestPathBase", "/pathBase" },
{ "owin.RequestQueryString", "name=value" },
};
var features = new OwinFeatureCollection(env);

var requestFeature = Get<IHttpRequestFeature>(features);
Assert.Equal(requestFeature.Method, "POST");
Assert.Equal(requestFeature.Method, HttpMethods.Post);
Assert.Equal(requestFeature.Path, "/path");
Assert.Equal(requestFeature.PathBase, "/pathBase");
Assert.Equal(requestFeature.QueryString, "?name=value");
Expand Down