better OPTIONS replies

2008-03-29 @ 13:44#

recently there has been a thread on the rest-discuss list concerning ways to improve replies to the HTTP OPTIONS method. lots of interesting stuff, not a whole lot of agreement. without getting involved in the fray, i decided to implement an improved reply to OPTIONS in the exyus web engine.

now, any OPTIONS requests sent to exyus will return at lear three headers:

  • Allow
  • X-Accept-Types
  • X-Content-Types
  • X-Acceptable

the last three are custom headers i've added. Calls to OPTIONS will return all the valid Accept and Content-Type headers. There is no indication of any filtering of the media types based on HTTP Methods. hey, you can't have everything!

also, any type the server throws 406 Not Acceptable, the X-Acceptable header is returned. this value indicates the media types acceptable for the requested call. of course, the Allow header is returned whenever the server issues a 405 Method Not Allowed, too.

here's a tracing that shows off these headers:

-- Typical call to OPTIONS for this URL
REQUEST: **************
OPTIONS /xcs/ugdata/ HTTP/1.1
content-type:text/junk
Host: localhost
Accept: */*

RESPONSE: **************
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Sat, 29 Mar 2008 17:56:05 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
X-Exyus: 0.6.3010.22781 2008-01
Allow: DELETE,GET,HEAD,OPTIONS,POST,PUT
X-Accept-Types: text/html,text/xml,application/json
X-Content-Types: text/xml,application/x-www-form-urlencoded,application/json
Cache-Control: private
Content-Length: 0


-- Not a Valid Accept Header for this URL
REQUEST: **************
GET /xcs/ugdata/ HTTP/1.1
accept:application/pdf
Host: localhost

RESPONSE: **************
HTTP/1.1 406 NotAcceptable
Server: Microsoft-IIS/5.1
Date: Sat, 29 Mar 2008 18:02:49 GMT
X-Powered-By: ASP.NET
Connection: close
X-AspNet-Version: 2.0.50727
X-Exyus: 0.6.3010.22781 2008-01
X-Acceptable: text/html,text/xml,application/json
Cache-Control: private
Content-Type: text/html

-- Not a Valid Method for this URL
REQUEST: **************
POST /xcs/editable/ HTTP/1.1
content-type:text/html
Host: localhost
Accept: */*

RESPONSE: **************
HTTP/1.1 405 POST Not Allowed.
Server: Microsoft-IIS/5.1
Date: Sat, 29 Mar 2008 17:56:41 GMT
X-Powered-By: ASP.NET
Connection: close
X-AspNet-Version: 2.0.50727
X-Exyus: 0.6.3010.22781 2008-01
Allow: DELETE,GET,HEAD,OPTIONS,PUT
X-Acceptable: text/html
Cache-Control: private
Content-Type: text/html

code