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

Modifying of HTTP headers in request metadata is no longer possible with Jetty 10 #9721

Closed
smitagarg1 opened this issue May 1, 2023 · 5 comments
Labels
Bug For general bugs on Jetty side Stale For auto-closed stale issues and pull requests

Comments

@smitagarg1
Copy link

smitagarg1 commented May 1, 2023

Jetty version(s)
Jetty 10.0.12

I was earlier using jetty version 9.4.43 and had following code to change empty content-type to "application/octet-stream"
in request metadata in order to avoid jetty not supporting empty content type and throwing 400 errors .

Jetty 9 code :
request.getMetaData()
.getFields()
.computeField(HttpHeader.CONTENT_TYPE, (httpHeader, httpFields) ->
new HttpField(httpHeader, MediaType.APPLICATION_OCTET_STREAM));

Jetty 10 : code changes made to use computeField from HttpFields.Mutable
HttpFields.build(request.getMetaData()
.getFields()).computeField(HttpHeader.CONTENT_TYPE, (httpHeader, httpFields) ->
new HttpField(httpHeader, MediaType.APPLICATION_OCTET_STREAM));

But it has started throwing 400 error again .It seems header value is not getting modified to APPLICATION_OCTET_STREAM from empty

Looks somewhat similar to #7818

@smitagarg1 smitagarg1 added the Bug For general bugs on Jetty side label May 1, 2023
@joakime
Copy link
Contributor

joakime commented May 1, 2023

Why are you doing that?
What goal are you trying to reach?

There are many paths you could have taken, and it seems you chose one of the most difficult paths.

@smitagarg1
Copy link
Author

This is how the application has been .My task here only is to upgrade the existing code as per jetty 10 requirements .

@gregw
Copy link
Contributor

gregw commented May 2, 2023

@smitagarg1 your code is just creating a new HttpFields instance, but not setting that back on the baseRequest. Try something like:

        MetaData.Request meta = baseRequest.getMetaData();
        HttpFields.Mutable newFields = HttpFields.build(meta.getFields());
        newFields.computeField(HttpHeader.CONTENT_TYPE, (httpHeader, httpFields) ->
            new HttpField(httpHeader, MediaType.APPLICATION_OCTET_STREAM));
        baseRequest.setMetaData(new MetaData.Request(
            meta.getMethod(),
            meta.getURI(),
            meta.getHttpVersion(),
            newFields));

Copy link

github-actions bot commented May 2, 2024

This issue has been automatically marked as stale because it has been a
full year without activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@github-actions github-actions bot added the Stale For auto-closed stale issues and pull requests label May 2, 2024
@joakime
Copy link
Contributor

joakime commented May 2, 2024

Question answered, closing.

@joakime joakime closed this as completed May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side Stale For auto-closed stale issues and pull requests
Projects
None yet
Development

No branches or pull requests

3 participants