Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RsFork incorrectly directs requests #1207

Open
volodya-lombrozo opened this issue Mar 10, 2023 · 1 comment
Open

RsFork incorrectly directs requests #1207

volodya-lombrozo opened this issue Mar 10, 2023 · 1 comment

Comments

@volodya-lombrozo
Copy link

We have the following routing code with RsFork and Maven 3.9.0:

return new RsFork(
     req,
     new FkTypes(
        "application/xml,text/xml",
         new RsWithType(raw, "text/xml")
     ),
     new FkTypes(
         "*/*",
         new RsXslt(new RsWithType(raw, "text/html"))
     )
);

The req variable has the Accept header set to */*.

Expected behaviour: The second new RsXslt(new RsWithType(raw, "text/html")) should be returned.

Actual behaviour: The first new RsWithType(raw, "text/xml") is returned instead.

Context: After the release of Maven 3.9.0, we started experiencing problems during the build of Rultor. One of the problems was a failed test that was related to RsFork. With Maven 3.8.7, everything works fine.

Environment:

Apache Maven 3.9.0 (9b58d2bad23a66be161c4664ef21ce219c2c8584)
Maven home: /usr/local/Cellar/maven/3.9.0/libexec
Java version: 19.0.2, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/19.0.2/libexec/openjdk.jdk/Contents/Home
Default locale: en_RU, platform encoding: UTF-8
OS name: "mac os x", version: "12.5", arch: "x86_64", family: "mac"
@NurmukhametovAlexey
Copy link
Contributor

NurmukhametovAlexey commented Apr 29, 2023

It seems that the cause of the problem is MediaType.matches method:


public boolean matches(final MediaType type) {
        final String star = "*";
        return (this.high.equals(star)
            || type.high.equals(star)
            || this.high.equals(type.high))
            && (this.low.equals(star)
            || type.low.equals(star)
            || this.low.equals(type.low));
    }

I would assume that this is the intended behavior - by supplying */* client says: "It doesn't matter to me what you send. I'll accept everything". Therefore RsFork goes with the first FkTypes, because application/xml,text/xml is a subset of everything.

The only thing I see problematic is that we are forced to duplicate code if want to make our last match-everything fork also a default fork. We'll need something similar to this:


Response rs = new RsXslt(new RsWithType(raw, "text/html"));
return new RsFork(
     req,
     new FkTypes(
         "match_nothing/except_stars",
         rs
     ),
     new FkTypes(
        "application/xml,text/xml",
         new RsWithType(raw, "text/xml")
     ),
     new FkTypes(
         "*/*",
         rs
     )
);

Is there something I`m missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants