1 /* ****************************************************************************
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\r
5 * This software is subject to the Microsoft Public License (Ms-PL).
\r
6 * A copy of the license can be found in the license.htm file included
\r
7 * in this distribution.
\r
9 * You must not remove this notice, or any other, from this software.
\r
11 * ***************************************************************************/
\r
13 namespace System.Web.Mvc {
\r
16 public static class HttpRequestExtensions {
\r
17 internal const string XHttpMethodOverrideKey = "X-HTTP-Method-Override";
\r
19 public static string GetHttpMethodOverride(this HttpRequestBase request) {
\r
20 if (request == null) {
\r
21 throw new ArgumentNullException("request");
\r
24 string incomingVerb = request.HttpMethod;
\r
26 if (!String.Equals(incomingVerb, "POST", StringComparison.OrdinalIgnoreCase)) {
\r
27 return incomingVerb;
\r
30 string verbOverride = null;
\r
31 string headerOverrideValue = request.Headers[XHttpMethodOverrideKey];
\r
32 if (!String.IsNullOrEmpty(headerOverrideValue)) {
\r
33 verbOverride = headerOverrideValue;
\r
36 string formOverrideValue = request.Form[XHttpMethodOverrideKey];
\r
37 if (!String.IsNullOrEmpty(formOverrideValue)) {
\r
38 verbOverride = formOverrideValue;
\r
41 string queryStringOverrideValue = request.QueryString[XHttpMethodOverrideKey];
\r
42 if (!String.IsNullOrEmpty(queryStringOverrideValue)) {
\r
43 verbOverride = queryStringOverrideValue;
\r
47 if (verbOverride != null) {
\r
48 if (!String.Equals(verbOverride, "GET", StringComparison.OrdinalIgnoreCase) &&
\r
49 !String.Equals(verbOverride, "POST", StringComparison.OrdinalIgnoreCase)) {
\r
50 incomingVerb = verbOverride;
\r
53 return incomingVerb;
\r