Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10449 (reopened defect)

Opened 1 year ago

Last modified 10 months ago

[PATCH] Rails 2.0.1 no longer accepts OPTIONS requests

Reported by: holoway Assigned to: core
Priority: normal Milestone: 2.0.2
Component: ActionPack Version: edge
Severity: normal Keywords:
Cc:

Description

Rails 2.0.1 has added the ability to ensure that the method being requested is a valid HTTP method. It defines the list of acceptable methods in actionpack/lib/action_controller/request.rb as:

ACCEPTED_HTTP_METHODS = Set.new(%w( get head put post delete ))

Missing from this list is OPTIONS. I (and many others) use OPTIONS request for several things:

  1. When building RESTful services, an OPTIONS request to a URL should return the methods that resource will respond to.
  2. When using mongrel behind a reverse proxy (such as Perlbal,) it is common to use an OPTIONS request to ensure that rails is ready to receive a new request (as opposed to mongrel simply accepting the TCP connection.)

Attached is a patch, enabling OPTIONS requests by default.

As a workaround, you can override the constant by placing:

module ActionController
  # HTTP methods which are accepted by default. 
  ACCEPTED_HTTP_METHODS = Set.new(%w( get head put post delete options ))
end

At the end of environments.rb, although this will generate a warning.

Attachments

add_options_to_accepted_http_methods.patch (1.1 kB) - added by holoway on 12/10/07 09:27:10.
Add OPTIONS to the list of allowed HTTP methods
broader_support_for_OPTIONS_method.diff (8.4 kB) - added by wzph on 01/30/08 22:31:02.
Broader support for OPTIONS.

Change History

12/10/07 09:27:10 changed by holoway

  • attachment add_options_to_accepted_http_methods.patch added.

Add OPTIONS to the list of allowed HTTP methods

12/10/07 10:06:19 changed by chuyeow

  • summary changed from Rails 2.0.1 no longer accepts OPTIONS requests to [PATCH] Rails 2.0.1 no longer accepts OPTIONS requests.

+1. Looks good, tests pass.

From http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html:

The OPTIONS method represents a request for information about the communication options available on the request/response chain identified by the Request-URI. This method allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval.

12/12/07 20:15:51 changed by holoway

A more concise way of working around this is adding:

ActionController::ACCEPTED_HTTP_METHODS << "options"

To environments.rb or an initializer.

12/17/07 00:06:28 changed by david

  • status changed from new to closed.
  • resolution set to fixed.

(In [8425]) Added OPTIONS to list of default accepted HTTP methods (closes #10449) [holoway]

01/30/08 22:30:01 changed by wzph

  • status changed from closed to reopened.
  • resolution deleted.

I think there are few other places where OPTIONS should be included. Attaching a patch against revision 8756 with those changes and some test cases. The main problem I encountered was with ActionController::TestProcess, not being able to do

options :blah

in a functional test, the way you can do

get :blah

Did I go too far or not far enough?

01/30/08 22:31:02 changed by wzph

  • attachment broader_support_for_OPTIONS_method.diff added.

Broader support for OPTIONS.

01/30/08 22:59:34 changed by bitsweat

I think the options :blah shortcut is too much, considering you can use process already. The routing update + tests look good though.

01/30/08 23:27:06 changed by wzph

Cheers. I would find the shortcut useful, but I may be an outlier in that respect.