Adding HTTP method constants

This commit is contained in:
Mikael Mengistu 2016-09-26 23:09:08 -07:00 committed by GitHub
parent 87cd79d6fc
commit 626332c5db
2 changed files with 68 additions and 2 deletions

View File

@ -0,0 +1,65 @@
// 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 HttpMethod
{
public static readonly string Connect = "CONNECT";
public static readonly string Delete = "DELETE";
public static readonly string Get = "GET";
public static readonly string Head = "HEAD";
public static readonly string Options = "OPTIONS";
public static readonly string Patch = "PATCH";
public static readonly string Post = "POST";
public static readonly string Put = "PUT";
public static readonly string Trace = "TRACE";
public static bool IsConnect(string method)
{
return object.ReferenceEquals(Connect, method) || StringComparer.OrdinalIgnoreCase.Equals(Connect, method);
}
public static bool IsDelete(string method)
{
return object.ReferenceEquals(Delete, method) || StringComparer.OrdinalIgnoreCase.Equals(Delete, method);
}
public static bool IsGet(string method)
{
return object.ReferenceEquals(Get, method) || StringComparer.OrdinalIgnoreCase.Equals(Get, method);
}
public static bool IsHead(string method)
{
return object.ReferenceEquals(Head, method) || StringComparer.OrdinalIgnoreCase.Equals(Head, method);
}
public static bool IsOptions(string method)
{
return object.ReferenceEquals(Options, method) || StringComparer.OrdinalIgnoreCase.Equals(Options, method);
}
public static bool IsPatch(string method)
{
return object.ReferenceEquals(Patch, method) || StringComparer.OrdinalIgnoreCase.Equals(Patch, method);
}
public static bool IsPost(string method)
{
return object.ReferenceEquals(Post, method) || StringComparer.OrdinalIgnoreCase.Equals(Post, method);
}
public static bool IsPut(string method)
{
return object.ReferenceEquals(Put, method) || StringComparer.OrdinalIgnoreCase.Equals(Put, method);
}
public static bool IsTrace(string method)
{
return object.ReferenceEquals(Trace, method) || StringComparer.OrdinalIgnoreCase.Equals(Trace, method);
}
}
}

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Xunit;
@ -25,7 +26,7 @@ namespace Microsoft.AspNetCore.Owin
{
var env = new Dictionary<string, object>
{
{ "owin.RequestMethod", "POST" },
{ "owin.RequestMethod", HttpMethod.Post },
{ "owin.RequestPath", "/path" },
{ "owin.RequestPathBase", "/pathBase" },
{ "owin.RequestQueryString", "name=value" },
@ -33,7 +34,7 @@ namespace Microsoft.AspNetCore.Owin
var features = new OwinFeatureCollection(env);
var requestFeature = Get<IHttpRequestFeature>(features);
Assert.Equal(requestFeature.Method, "POST");
Assert.Equal(requestFeature.Method, HttpMethod.Post);
Assert.Equal(requestFeature.Path, "/path");
Assert.Equal(requestFeature.PathBase, "/pathBase");
Assert.Equal(requestFeature.QueryString, "?name=value");