Hello,

I know it's unusual, but one of the clients I'm using (jQuery) sends a 
"Content-Type: application/x-www-form-urlencoded" header with its GET 
requests (because there's some data that's serialized in the query part 
of the URI, see [1][2]).
I've looked at the HTTP specification, but I can't find where it says 
it's forbidden to send that header with a GET.

The problem is that it confuses the way the content-type negotiation 
works with the @Get annotation. I've put an example here 
<http://gist.github.com/496447>.

        public static class SampleResource extends ServerResource {
                @Override
                public void doInit() {
                        setNegotiated(true);
                }

                @Get("json")
                public Representation toJson() {
                        return new StringRepresentation("{ 'message': 'hello' 
}",
                                        MediaType.APPLICATION_JSON);
                }

                @Get("html")
                public Representation toHtml() {
                        return new 
StringRepresentation("<html><body>Hello</body></html>",
                                        MediaType.TEXT_HTML);
                }
        }


The problem is that, if there's "Content-Type: 
application/x-www-form-urlencoded" in the GET request, the content-type 
negotiation fails and the default media type is used (not the one 
obtained from the Accept header).

Using @Get("*:json") and @Get("*:html") instead of @Get("json") and 
@Get("html"), respectively, seems to fix the problem, but it seems 
unnatural.
I'm just wondering if it would be sensible and/or possible to make the 
content-type negotiation ignore the Content-Type header in the request 
for requests with no entity, or perhaps if "*:" could be implied anyway 
for those cases.


Best wishes,

Bruno.



[1] http://dev.jquery.com/ticket/6674
[2] http://dev.jquery.com/ticket/6811

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2639896

Reply via email to