Question

The RFC 2616 HTTP/1.1 definition states that the following common HTTP methods exist:

GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT

But the System.Web.Mvc.HttpVerbs enum is missing TRACE, OPTIONS & CONNECT.

I've got an action filter which picks up the HttpVerb from the request in order to make certain decisions (for example, if a request is PUT'ing a model of base type A, then i set some data), so this utility code is throwing an ArgumentOutOfRangeException for requests of the last three (mostly OPTIONS - looks like it's coming from Google Translate):

public static HttpVerbs GetHttpVerb(this HttpRequestBase httpRequestBase)
{
    switch (httpRequestBase.HttpMethod)
    {
        case "GET":
            return HttpVerbs.Get;
        case "POST":
            return HttpVerbs.Post;
        case "PUT":
            return HttpVerbs.Put;
        case "DELETE":
            return HttpVerbs.Delete;
        case "HEAD":
            return HttpVerbs.Head;    
        default:
            throw new ArgumentOutOfRangeException("httpRequestBase");
    }
}

Not sure how to get around this - any ideas?

Only thing i can think of is change all referencing code to check the raw HTTP method first, then only call the utility if it's not TRACE, OPTIONS or CONNECT. Which is kinda hacky.

Why is it missing from the enum class? Is there a specific reason for it? Can MVC simply not handle requests of these types?

By the sounds of the OPTIONS method, it shouldn't even get to MVC, and it should be handled by IIS itself?

Was it helpful?

Solution

Ended up creating my own enum and using that.

public enum HttpVerb
{
    Get,
    Head,
    Post,
    Put,
    Delete,
    Trace,
    Options,
    Connect
}

MVC still seems to handle requests of type OPTIONS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top