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

JSON in POST request treated as body attribute in HttpPostStandardRequestDecoder #13981

Closed
gniadeck opened this issue Apr 17, 2024 · 0 comments · Fixed by #13998
Closed

JSON in POST request treated as body attribute in HttpPostStandardRequestDecoder #13981

gniadeck opened this issue Apr 17, 2024 · 0 comments · Fixed by #13998

Comments

@gniadeck
Copy link
Contributor

gniadeck commented Apr 17, 2024

Expected behavior

JSON in POST request shouldn't be counted as body attribute in HttpPostStandardRequestDecoder, as in releases <4.1.108-Final (checked on 4.1.107.Final and 4.1.106.Final)

Actual behavior

JSON in POST request is treated as body attribute in HttpPostStandardRequestDecoder, and an attribute is created with key equal to JSON and empty value

Steps to reproduce

Send a POST request to netty >=4.1.108-Final, decode the request using HttpPostRequestDecoder and check .getBodyHttpDatas() The resulting list will contain Attribute HttpData where the key is a JSON sent by a client, and value is empty

Minimal yet complete reproducer code (or URL to code)

public class NettyReproduction {
    public static void main(String[] args) {
        FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/netty/reproduction",
            Unpooled.wrappedBuffer("""
                {
                    "netty": "reproduction"
                }
                """.getBytes(StandardCharsets.UTF_8)));
        var decoder = new HttpPostRequestDecoder(request);
        var result = decoder.getBodyHttpDatas();
        System.out.println(result); 
    }
}

results in:
[Mixed: { "netty": "reproduction"}=] on 4.1.109.Final and 4.1.108.Final

but results in:
[] on 4.1.107.Final and 4.1.106.Final

Netty version

as above

JVM version (e.g. java -version)

Java 21

OS version (e.g. uname -a)

Windows 10,
and @Rufusmen reproduced on Linux (Ubuntu 22.04.4 LTS x86_64)

We suspect that the reason for such change is this PR: #13908 , thus we are wondering if such behaviour is desired, if the decoder decodes something different than x-www-form-urlencoded

@gniadeck gniadeck changed the title JSON in POST request treated as body attribute JSON in POST request treated as body attribute in HttpPostStandardRequestDecoder Apr 17, 2024
gniadeck added a commit to gniadeck/netty that referenced this issue Apr 23, 2024
gniadeck added a commit to gniadeck/netty that referenced this issue Apr 23, 2024
Motivation:

This is a fix for issue netty#13981 that reports a changed behaviour of HttpPostStandardRequestDecoder after this PR - netty#13908

Because HttpPostStandardRequestDecoder changed the contract, some code implementations relying on certain parsing are failing

Modification:

This PR makes sure, that the edge case handling for form data happenes only when the content is in fact form data

Result:

Fixes netty#13981
normanmaurer pushed a commit that referenced this issue Apr 27, 2024
Motivation:

This is a fix for issue #13981 that reports a changed behaviour of
HttpPostStandardRequestDecoder after this PR -
#13908

Because HttpPostStandardRequestDecoder changed the contract, some code
implementations relying on certain parsing are failing


Modification:

This PR makes sure, that the edge case handling for form body happenes
only when the content is in fact form body

Result:

Fixes #13981
normanmaurer pushed a commit that referenced this issue Apr 27, 2024
Motivation:

This is a fix for issue #13981 that reports a changed behaviour of
HttpPostStandardRequestDecoder after this PR -
#13908

Because HttpPostStandardRequestDecoder changed the contract, some code
implementations relying on certain parsing are failing


Modification:

This PR makes sure, that the edge case handling for form body happenes
only when the content is in fact form body

Result:

Fixes #13981
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

Successfully merging a pull request may close this issue.

1 participant