#961 enhancement
ronin-24025 (at lighthouseapp)

Ajax.Request.setRequestHeaders sets Content-Type header as Content-type and sets it regardless of whether it's provided to the Ajax.Request interface (and other issues).

Reported by ronin-24025 (at lighthouseapp) | December 9th, 2009 @ 10:26 AM

Ajax.Request.setRequestHeaders sets the 'Content-Type' header as 'Content-type' and sets it regardless of whether it's provided to the Ajax.Request interface:

headers['Content-type'] = this.options.contentType +
        (this.options.encoding ? '; charset=' + this.options.encoding : '');

Even if one passes an empty string for the contentType option, the header is still set.

The interface of the Ajax.Request object has other problems:

  1. Too many implicit defaults (accept, content type, charset etc).
  2. Does not model the interface of HTTP.
  3. 'requestHeaders' are provided as an option, 'encoding' as an option, 'contentType' as an option, when 'encoding' should be specified as 'charset' as part of the 'Content-Type' header which should be a subset of 'requestHeaders'.
  4. If the request headers are provided as 'requestHeaders' then the request body needs to be provided as 'requestBody' not as 'postBody'. REST concepts such as method, uri, headers, parameters, representation should not be fused (e.g. 'XMLHttpRequest' which fuses the content type and the protocol, or 'postBody' which fuses the method and the representation).
  5. 'requestHeaders' smells.
  6. For method overriding, the 'X-Http-Method-Override' header would be better than the '_method' parameter.
  7. It's not memorable. One has to keep looking up the Ajax options in the documentation (and where things get implicit, in the implementation).

Here's a better (and more memorable) interface:

Http.get/set/unset(uri, options) where 'options' has the following properties: 'headers', 'parameters', 'representation', onSuccess, 'onTimeout', 'onFailure', and where the response object passed to the callbacks has the following properties: 'status', 'headers', 'representation'.

Http.delete can't be used as 'delete' is a reserved word. Http.set does a POST with the 'X-Http-Method-Override' header set to 'PUT' so as to be idempotent where the server supports PUT. Http.unset does a POST with the 'X-Http-Method-Override' header set to 'DELETE'.

Comments and changes to this ticket

  • Tobie Langel

    Tobie Langel December 9th, 2009 @ 05:57 PM

    • State changed from “new” to “enhancement”
    • Tag changed from bug, enhancement, section:ajax to section:ajax

    Interesting suggestions. Needs discussion on the core mailing list of the proposed API, plans for deprecation, handling backwards compatibility, etc.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket