5 // Marek Safar <marek.safar@gmail.com>
7 // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 namespace System.Net.Http
31 public class HttpMethod : IEquatable<HttpMethod>
33 static readonly HttpMethod delete_method = new HttpMethod ("DELETE");
34 static readonly HttpMethod get_method = new HttpMethod ("GET");
35 static readonly HttpMethod head_method = new HttpMethod ("HEAD");
36 static readonly HttpMethod options_method = new HttpMethod ("OPTIONS");
37 static readonly HttpMethod post_method = new HttpMethod ("POST");
38 static readonly HttpMethod put_method = new HttpMethod ("PUT");
39 static readonly HttpMethod trace_method = new HttpMethod ("TRACE");
41 readonly string method;
43 public HttpMethod (string method)
45 if (string.IsNullOrEmpty (method))
46 throw new ArgumentException ("method");
48 Headers.Parser.Token.Check (method);
53 public static HttpMethod Delete {
59 public static HttpMethod Get {
65 public static HttpMethod Head {
71 public string Method {
77 public static HttpMethod Options {
79 return options_method;
83 public static HttpMethod Post {
89 public static HttpMethod Put {
95 public static HttpMethod Trace {
101 public static bool operator == (HttpMethod left, HttpMethod right)
103 if ((object) left == null || (object) right == null)
104 return ReferenceEquals (left, right);
106 return left.Equals (right);
109 public static bool operator != (HttpMethod left, HttpMethod right)
111 return !(left == right);
114 public bool Equals(HttpMethod other)
116 return string.Equals (method, other.method, StringComparison.OrdinalIgnoreCase);
119 public override bool Equals (object obj)
121 var other = obj as HttpMethod;
122 return !ReferenceEquals (other, null) && Equals (other);
125 public override int GetHashCode ()
127 return method.GetHashCode ();
130 public override string ToString ()