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

Invalid Accept header results in 500 and a logged exception. #8666

Closed
barchetta opened this issue Apr 16, 2024 · 1 comment
Closed

Invalid Accept header results in 500 and a logged exception. #8666

barchetta opened this issue Apr 16, 2024 · 1 comment
Assignees
Labels
3.x Issues for 3.x version branch 4.x Version 4.x SE webserver

Comments

@barchetta
Copy link
Member

barchetta commented Apr 16, 2024

Environment Details

  • Helidon Version: 4.0.7, 3.2.7, 2.6.7
  • Helidon SE

Problem Description

If you make a request with a malformed Accept header the server logs an exception and returns an Http status of 500. One would expect a more restrained response, for example: log (at most) a warning and return a 400.

I was able to reproduce some variant of this on Helidon 2, 3 and 4.

Steps to reproduce

Generate the a Quickstart SE project and start it. Then do (note badly formed mime type application.json):

curl -v -H 'Accept: application.json' -X GET http://localhost:8080/observe/metrics

The server returns 500:

> GET /observe/metrics HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.4.0
> Accept: application.json
>
< HTTP/1.1 500 Internal Server Error
< Date: Tue, 16 Apr 2024 14:45:14 -0700
< Connection: keep-alive
< Content-Length: 41
< Content-Type: text/plain
<
* Connection #0 to host localhost left intact
Cannot parse media type: application.json

and logs an exception:

2024.04.16 14:45:14.704 Internal server error
io.helidon.http.RequestException: Cannot parse media type: application.json
	at io.helidon.http.RequestException$Builder.build(RequestException.java:139)
	at io.helidon.webserver.http.ErrorHandlers.unhandledError(ErrorHandlers.java:203)
	at io.helidon.webserver.http.ErrorHandlers.lambda$handleError$1(ErrorHandlers.java:182)
	at java.base/java.util.Optional.ifPresentOrElse(Optional.java:198)
	at io.helidon.webserver.http.ErrorHandlers.handleError(ErrorHandlers.java:181)
	at io.helidon.webserver.http.ErrorHandlers.runWithErrorHandling(ErrorHandlers.java:118)
	at io.helidon.webserver.http.Filters$FilterChainImpl.proceed(Filters.java:121)
	at io.helidon.webserver.observe.metrics.MetricsFeature.lambda$configureVendorMetrics$2(MetricsFeature.java:90)
	at io.helidon.webserver.http.Filters$FilterChainImpl.proceed(Filters.java:119)
	at io.helidon.webserver.http.Filters.executeFilters(Filters.java:87)
	at io.helidon.webserver.http.Filters.lambda$filter$0(Filters.java:83)
	at io.helidon.webserver.http.ErrorHandlers.runWithErrorHandling(ErrorHandlers.java:75)
	at io.helidon.webserver.http.Filters.filter(Filters.java:83)
	at io.helidon.webserver.http.HttpRoutingImpl.route(HttpRoutingImpl.java:73)
	at io.helidon.webserver.http1.Http1Connection.route(Http1Connection.java:357)
	at io.helidon.webserver.http1.Http1Connection.handle(Http1Connection.java:194)
	at io.helidon.webserver.ConnectionHandler.run(ConnectionHandler.java:165)
	at io.helidon.common.task.InterruptableTask.call(InterruptableTask.java:47)
	at io.helidon.webserver.ThreadPerTaskExecutor$ThreadBoundFuture.run(ThreadPerTaskExecutor.java:239)
	at java.base/java.lang.VirtualThread.run(VirtualThread.java:309)
Caused by: java.lang.IllegalArgumentException: Cannot parse media type: application.json
	at io.helidon.common.media.type.MediaTypeImpl.parse(MediaTypeImpl.java:38)
	at io.helidon.common.media.type.MediaTypes.create(MediaTypes.java:177)
	at io.helidon.http.HttpMediaType$Builder.parse(HttpMediaType.java:313)
	at io.helidon.http.HttpMediaType.create(HttpMediaType.java:76)
	at io.helidon.http.ServerRequestHeadersImpl.acceptedTypes(ServerRequestHeadersImpl.java:88)
	at io.helidon.http.ServerRequestHeaders.bestAccepted(ServerRequestHeaders.java:139)
	at io.helidon.webserver.observe.metrics.MetricsFeature.bestAccepted(MetricsFeature.java:131)
	at io.helidon.webserver.observe.metrics.MetricsFeature.getMatching(MetricsFeature.java:184)
	at io.helidon.webserver.observe.metrics.MetricsFeature.getAll(MetricsFeature.java:177)
	at io.helidon.webserver.http.HttpRoutingImpl$RoutingExecutor.doRoute(HttpRoutingImpl.java:165)
	at io.helidon.webserver.http.HttpRoutingImpl$RoutingExecutor.call(HttpRoutingImpl.java:124)
	at io.helidon.webserver.http.HttpRoutingImpl$RoutingExecutor.call(HttpRoutingImpl.java:102)
	at io.helidon.webserver.http.ErrorHandlers.runWithErrorHandling(ErrorHandlers.java:75)
	... 14 more
@barchetta barchetta added SE webserver 3.x Issues for 3.x version branch 4.x Version 4.x labels Apr 16, 2024
@spericas
Copy link
Member

I can take a look, will start with 4.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issues for 3.x version branch 4.x Version 4.x SE webserver
Projects
Archived in project
Development

No branches or pull requests

2 participants