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

Commit 626332c

Browse files
authored
Adding HTTP method constants
1 parent 87cd79d commit 626332c

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
6+
namespace Microsoft.AspNetCore.Http
7+
{
8+
public static class HttpMethod
9+
{
10+
public static readonly string Connect = "CONNECT";
11+
public static readonly string Delete = "DELETE";
12+
public static readonly string Get = "GET";
13+
public static readonly string Head = "HEAD";
14+
public static readonly string Options = "OPTIONS";
15+
public static readonly string Patch = "PATCH";
16+
public static readonly string Post = "POST";
17+
public static readonly string Put = "PUT";
18+
public static readonly string Trace = "TRACE";
19+
20+
public static bool IsConnect(string method)
21+
{
22+
return object.ReferenceEquals(Connect, method) || StringComparer.OrdinalIgnoreCase.Equals(Connect, method);
23+
}
24+
25+
public static bool IsDelete(string method)
26+
{
27+
return object.ReferenceEquals(Delete, method) || StringComparer.OrdinalIgnoreCase.Equals(Delete, method);
28+
}
29+
30+
public static bool IsGet(string method)
31+
{
32+
return object.ReferenceEquals(Get, method) || StringComparer.OrdinalIgnoreCase.Equals(Get, method);
33+
}
34+
35+
public static bool IsHead(string method)
36+
{
37+
return object.ReferenceEquals(Head, method) || StringComparer.OrdinalIgnoreCase.Equals(Head, method);
38+
}
39+
40+
public static bool IsOptions(string method)
41+
{
42+
return object.ReferenceEquals(Options, method) || StringComparer.OrdinalIgnoreCase.Equals(Options, method);
43+
}
44+
45+
public static bool IsPatch(string method)
46+
{
47+
return object.ReferenceEquals(Patch, method) || StringComparer.OrdinalIgnoreCase.Equals(Patch, method);
48+
}
49+
50+
public static bool IsPost(string method)
51+
{
52+
return object.ReferenceEquals(Post, method) || StringComparer.OrdinalIgnoreCase.Equals(Post, method);
53+
}
54+
55+
public static bool IsPut(string method)
56+
{
57+
return object.ReferenceEquals(Put, method) || StringComparer.OrdinalIgnoreCase.Equals(Put, method);
58+
}
59+
60+
public static bool IsTrace(string method)
61+
{
62+
return object.ReferenceEquals(Trace, method) || StringComparer.OrdinalIgnoreCase.Equals(Trace, method);
63+
}
64+
}
65+
}

test/Microsoft.AspNetCore.Owin.Tests/OwinFeatureCollectionTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Collections.Generic;
5+
using Microsoft.AspNetCore.Http;
56
using Microsoft.AspNetCore.Http.Features;
67
using Xunit;
78

@@ -25,15 +26,15 @@ public void OwinHttpEnvironmentCanBeCreated()
2526
{
2627
var env = new Dictionary<string, object>
2728
{
28-
{ "owin.RequestMethod", "POST" },
29+
{ "owin.RequestMethod", HttpMethod.Post },
2930
{ "owin.RequestPath", "/path" },
3031
{ "owin.RequestPathBase", "/pathBase" },
3132
{ "owin.RequestQueryString", "name=value" },
3233
};
3334
var features = new OwinFeatureCollection(env);
3435

3536
var requestFeature = Get<IHttpRequestFeature>(features);
36-
Assert.Equal(requestFeature.Method, "POST");
37+
Assert.Equal(requestFeature.Method, HttpMethod.Post);
3738
Assert.Equal(requestFeature.Path, "/path");
3839
Assert.Equal(requestFeature.PathBase, "/pathBase");
3940
Assert.Equal(requestFeature.QueryString, "?name=value");

0 commit comments

Comments
 (0)