JeroenWyseur JeroenWyseur - 3 months ago 9
reST (reStructuredText) Question

Can I change the headers of the HTTP request sent by the browser?

I'm looking into a restful design and would like to use the HTTP methods (

POST
,
GET
, ...) and HTTP headers as much as possible. I already found out that the HTTP methods
PUT
and
DELETE
are not supported from the browser.

Now I'm looking to get different representations of the same resource and would like to do this by changing the
Accept
header of the request. Depending on this
Accept
header, the server can serve a different view on the same resource.

Problem is that I didn't find a way to tell my browser to change this header.

The
<a..>
tag has a type attribute, that can have a mime type, looked like a good candidate but the header was still the browser default (in Firefox it can be changed in
about:config
with the
network.http.accept.default
key).

Answer

I don't think it's possible to do it in the way you are trying to do it.

Indication of the accepted data format is usually done through adding the extension to the resource name. So, if you have resource like

/resources/resource

and GET /resources/resource returns its HTML representation, to indicate that you want its XML representation instead, you can use following pattern:

/resources/resource.xml

You have to do the accepted content type determination magic on the server side, then.

Or use Javascript as James suggests.

Comments