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

Requests without an Accept header are not accepted #497

Closed
pedroigor opened this issue May 26, 2022 · 7 comments · Fixed by #498
Closed

Requests without an Accept header are not accepted #497

pedroigor opened this issue May 26, 2022 · 7 comments · Fixed by #498

Comments

@pedroigor
Copy link
Contributor

pedroigor commented May 26, 2022

Making a request without an Accept header ends up with the following response:

curl -v -H "Accept:" -H "accept-encoding: identity" http://localhost:8080/metrics
* About to connect() to localhost port 8080 (#0)
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /metrics HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:8080
> accept-encoding: identity
>
< HTTP/1.1 406 Not Acceptable
< content-length: 69
<
* Connection #0 to host localhost left intact
* 

In this case (the absence of an Accept header), the server should assume that the client accepts all types, i.e. /. This is defined in the HTTP spec here: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

If no Accept header field is present, then it is assumed that the client accepts all media types.

Looks like the issue is on how the empty Accept header is handled here https://github.com/smallrye/smallrye-metrics/blob/main/implementation/src/main/java/io/smallrye/metrics/MetricsRequestHandler.java#L229.

If empty, the server should respond with the preferred content type instead of not accepting the request. Perhaps use application/json as the default?

FYI, this behavior was found in Quarkus applications using the quarkus-smallrye-metrics.

If the issue makes sense, I can send a PR.

@jmartisk
Copy link
Member

Hi; seems you're right, except the detail that the default for a missing Accept header should be OpenMetrics (text/plain), as per https://download.eclipse.org/microprofile/microprofile-metrics-3.0/microprofile-metrics-spec-3.0.html#rest-api, not JSON

PRs welcome :)

@jmartisk
Copy link
Member

It's a bit complicated with branches in this repo right now, but to get it fixed in Quarkus, the most important branch for a PR would be main, and also jakarta to make sure the problem doesn't reappear after we migrate to Jakarta EE 10.
micrometer branch might be applicable too, that's currently mostly under the direction of @Channyboy

@pedroigor
Copy link
Contributor Author

@jmartisk Sent a PR to main. Should I sent to jarkarta branch now or wait first for your review/merge?

@jmartisk
Copy link
Member

Main PR merged, if you're eager please send the same for jakarta, otherwise I will do it myself, no problem
Let's leave micrometer to @Channyboy so he can add it too if appropriate
Thanks!

@pedroigor
Copy link
Contributor Author

Tk u. I'll send it now to jakarta.

@jmartisk
Copy link
Member

Thanks. I will see to it that the fix is propagated into Quarkus 2.10.0 and 2.9.3

@pedroigor
Copy link
Contributor Author

Ok

Channyboy pushed a commit to Channyboy/smallrye-metrics that referenced this issue Oct 20, 2022
tevans78 added a commit to tevans78/open-liberty that referenced this issue Jan 26, 2023
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.

2 participants