Michael Ekoka
Michael Ekoka

Reputation: 20088

REST: Is http code 300 appropriate in this redirect situation?

I have a multi-locales website. I need to redirect users to their locale when they access the site without the locale code in the url.

e.g.

http://www.mysite.com automatically redirected to either http://www.mysite.com/uk or http://www.mysite.com/us

I'm looking at rfc2616 and I'm hesitating to use Code 300 (Multiple Choices):

The requested resource corresponds to any one of a set of representations, each with its own specific location, and agent- driven negotiation information (section 12) is being provided so that the user (or user agent) can select a preferred representation and redirect its request to that location.

Unless it was a HEAD request, the response SHOULD include an entity containing a list of resource characteristics and location(s) from which the user or user agent can choose the one most appropriate. The entity format is specified by the media type given in the Content-Type header field.

Depending upon the format and the capabilities of the user agent, selection of the most appropriate choice MAY be performed automatically. However, this specification does not define any standard for such automatic selection.

If the server has a preferred choice of representation, it SHOULD include the specific URI for that representation in the Location field;

I think I understand, but the wording still makes it a bit cryptic for me. Can someone familiar with response codes confirm if I'm on the right track and explain the following excerpts?

  • [...] and agent-driven negotiation information is being provided [...]
  • Unless it was a HEAD request, the response SHOULD include an entity containing a list of resource characteristics and location(s) [...]
  • Upvotes: 6

    Views: 1868

    Answers (2)

    annakata
    annakata

    Reputation: 75794

    I believe this is the correct response, yes. In fact I think it's the only choice if you do want to handle this as a response (and can't do geo lookups for example) since all of the other 3xx range responses are for determinate results (except the weird 305 proxy).

    As for the excerpts:

    ...and agent-driven negotiation information is being provided...

    The intention here is to express that amongst the choices being made are choices which are based on the characteristics of the user-agent (which are infinitely varied potentially) which are typically conveyed in the accept headers and the user-agent header itself. Negotiation is a bit of a confusing term perhaps, but the concept it's referring to is the determination between the agent and the server of what kind of response is appropriate.

    Unless it was a HEAD request, the response SHOULD include an entity containing a list of resource characteristics and location(s)...

    HEAD requests are designed to return response headers only (so you can do things like cheaply checking for content updates). They therefore specifically don't want a response body so don't need to provide the list of potential choices you would for 300 to a GET or POST request.

    Upvotes: 0

    Darrel Miller
    Darrel Miller

    Reputation: 142044

    In your case I don't think you want "agent driven negotiation". In your case, your server should be able to select the redirect location from the accept-lang header. I think you can use the 303 redirect.

    Agent driven negotiation is only used when the server does not know what the representation the client wants. In those cases, the server would return a list of links with the different options available. The agent would then select representation it wants.

    You would use agent driven negotiation if you wanted some javascript code to process the 300 response and display a list of options to the user so that the user can select the desired language.

    Upvotes: 1

    Related Questions