Page MenuHomePhabricator

Wikidata should not return 406 Not Acceptable
Closed, ResolvedPublic

Description

Attempting to use action=raw on a page using the Wikidata content model gives a HTTP 406 error:

http://wikidata-test-repo.wikimedia.de/w/index.php?title=Data:Q207&action=raw&ctype=text/css

This error is reserved for instances where the browser's "Accept" header does not list anything that the server can provide. [1] But modern browsers pass in "*/*" for this header, meaning all content types are acceptable, so error 406 should never be seen.

Instead of serving 406, either the raw page content (as stored in the DB) should indeed be provided, or a more appropriate error should be provided.

[1] https://tools.ietf.org/html/rfc2616#section-10.4.7


Version: unspecified
Severity: normal

Details

Reference
bz40032

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 1:06 AM
bzimport set Reference to bz40032.
bzimport added a subscriber: Unknown Object (MLST).

According to the spec, you are right. I can't really think of a good error code though.

I removed support for action=raw for non-text content as a response to an explicit request from the core team - I think it was Tim Starling. The reason is that the current expectation is that this will return wikitext, and returning JSON or XML or whatever would break that expectation. Also, while we can communicate the serialization format using the ContentType header, there is no way to tell the client which content *model* is used, which makes it impossible to interpret the returned data.

That, and the fact that action=raw is deprecated anyway.

So, what error code should be used? A plain 400? Btw, ctype=text/css is kind of like an accept header, and it's incompatible with the content model used in Q207, so... it kind of is a 406. Just that the format wasn't specified in the accept header.

i'd say 404. what the url is requesting does not exist

What about 501 Not Implemented?

501 refers specifically to a HTTP method, but this is a simple GET and a GET is supported.

Why does an HTTP error need to be served at all? Couldn't there be a simple notice like we used to serve for empty pages be displayed? e.g.

/* This page uses a content model that is not supported by action=raw */

(In reply to comment #5)

Why does an HTTP error need to be served at all? Couldn't there be a simple
notice like we used to serve for empty pages be displayed? e.g.

/* This page uses a content model that is not supported by action=raw */

Because *programs* use this, and programs don't understand comments. They'd just take that as the actual page text, possibly using it as the basis for an edit etc.

We can serve such a comment, but it must be accompanied by a 4xx response code.

A quick research shows these options:

418: "I'm a tea pot" (RFC 2324). It's defined thus:

Any attempt to brew coffee with a teapot should result in the error
code "418 I'm a teapot". The resulting entity body MAY be short and
stout.

Thanks to Johl for that idea. I think however we might rather want to go with this:

415: "Unsupported Media Type" (RFC 2616). Sounds good:

The server is refusing to service the request because the entity of
the request is in a format not supported by the requested resource
for the requested method.

Closed older resolved bugs as verified.