Alex Rivera | Logout

Why HttpRequest.HttpMethod is string instead of Enum?

Asked 2011-07-17T06:17:20.200
28

In the Reference of HttpRequest.HttpMethod of .NET Framework, request type is declared with System.String type.

In RFC 2616 all HTTP request methods are declared (e.g. POST, GET, PUT, DELETE...).

There's also similar behavior in HttpWebRequest and WebRequest classes of .NET.

Java has the similar approach on HttpURLConnection#setRequestMethod(String) method.

Why do these language designers do not consider implementing an enum for those HTTP methods?

Do you have an idea?

Edit
Report

2 Answers

3

if HTTP Comes with a new method, then java and C# needs to update their enum. When will they update it? Will they release a patch? or will be updated in next version? So defining a enum on values which they dont control is not a wise decision.

answered 2011-07-17T06:22:51.253
2

As Damien mentions, RFC2616 only defines the common methods. HTTP, like XML, is a protocol that can be extended to support other formats.

For instance, suppose I wanted to implement a special method called "Encrypt". If the HTTP library were enums, it would fail and likely throw an exception. Of course the client would have to know about this special request type, which is why most extensions are done via headers rather than commands.

HTTP is an extensible protocol, but few people actually do extend it.

Consider this simple example:

<form method="Foo" action="http://someurl"></form>

Since "method" is just text, and the user could put anything there, then the HTTP handler has to be able to handle it, correct?

EDIT:

As it turns out, the HTML 4 specification only allows for GET and POST to be valid values, but HTTP goes beyond that.

answered 2011-07-17T06:30:07.010

Your Answer