forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpMethodHelper.cs
More file actions
63 lines (53 loc) · 1.98 KB
/
HttpMethodHelper.cs
File metadata and controls
63 lines (53 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// 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.Net.Http;
namespace System.Web.Http
{
/// <summary>
/// Various helper methods for the static members of <see cref="HttpMethod"/>.
/// </summary>
internal static class HttpMethodHelper
{
/// <summary>
/// Gets the static <see cref="HttpMethod"/> instance for any given HTTP method name.
/// </summary>
/// <param name="method">The HTTP request method.</param>
/// <returns>An existing static <see cref="HttpMethod"/> or a new instance if the method was not found.</returns>
internal static HttpMethod GetHttpMethod(string method)
{
if (String.IsNullOrEmpty(method))
{
return null;
}
if (String.Equals("GET", method, StringComparison.OrdinalIgnoreCase))
{
return HttpMethod.Get;
}
if (String.Equals("POST", method, StringComparison.OrdinalIgnoreCase))
{
return HttpMethod.Post;
}
if (String.Equals("PUT", method, StringComparison.OrdinalIgnoreCase))
{
return HttpMethod.Put;
}
if (String.Equals("DELETE", method, StringComparison.OrdinalIgnoreCase))
{
return HttpMethod.Delete;
}
if (String.Equals("HEAD", method, StringComparison.OrdinalIgnoreCase))
{
return HttpMethod.Head;
}
if (String.Equals("OPTIONS", method, StringComparison.OrdinalIgnoreCase))
{
return HttpMethod.Options;
}
if (String.Equals("TRACE", method, StringComparison.OrdinalIgnoreCase))
{
return HttpMethod.Trace;
}
return new HttpMethod(method);
}
}
}