playframework / playframework/play1

Http Request resolveFormat function

Open
#1,164 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.6k
Forks
671
Avg merge
12d 15h
Merged PRs (30d)
1

Description

Hi,I find an issue in play1.2.7.the code is located at play.mvc.Http.java`s inner class Request.
the commnet says order is not same as the function resolveFormat it work.
Mybe the 5th and 6th if statement should exchange

`/**
* Automatically resolve request format from the Accept header
* (in this order : html > xml > json > text)
*/
public void resolveFormat() {

        if (format != null) {
            return;
        }

        if (headers.get("accept") == null) {
            format = "html".intern();
            return;
        }

        String accept = headers.get("accept").value();

        if (accept.indexOf("application/xhtml") != -1 || accept.indexOf("text/html") != -1 || accept.startsWith("*/*")) {
            format = "html".intern();
            return;
        }

        if (accept.indexOf("application/xml") != -1 || accept.indexOf("text/xml") != -1) {
            format = "xml".intern();
            return;
        }

        if (accept.indexOf("text/plain") != -1) {
            format = "txt".intern();
            return;
        }

        if (accept.indexOf("application/json") != -1 || accept.indexOf("text/javascript") != -1) {
            format = "json".intern();
            return;
        }

        if (accept.endsWith("*/*")) {
            format = "html".intern();
            return;
        }
    }`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in play.mvc.Http.java at the Request inner class and read resolveFormat() alongside its comment describing the html > xml > json > text order. Check the conditional sequence against that documented order, then verify that the function resolves matching Accept headers in the intended precedence.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.