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

Add Accept header to 415 responses #2663

Open
komape opened this issue Oct 21, 2024 · 4 comments · May be fixed by #2672
Open

Add Accept header to 415 responses #2663

komape opened this issue Oct 21, 2024 · 4 comments · May be fixed by #2672
Assignees
Milestone

Comments

@komape
Copy link
Contributor

komape commented Oct 21, 2024

Describe the feature

If the content type of a request is not matching the accepted content types, a 415 Unsupported Media Type status is returned. According to the mdn web docs for the HTTP status 415 and the RFC 9110 for HTTP semantics, an Accept header with the accepted content types should be returned as well. This is currently missing and should be added.

For example, this endpoint accepts JSON and CSV:

router.route()
  .consumes("application/json")
  .consumes("text/csv")
  .handler(ctx -> {
    // handle request
  });

In case, the client does not provide any content type or a wrong one, for example text/plain, the response should be as follows:

HTTP/1.1 415 Unsupported Media Type
# other fields
Accept: application/json, text/csv
Content-Length: 0

This is a follow up from #2656.

Use cases

This feature fulfills the offical semantics for a 415 status.

Additionally, the client gets to know what type of content is accepted without looking for documentation.

Contribution

I would like to do it but I cannot say until when.

When is v5.0.0 supposed to be released?

@tsegismont
Copy link
Contributor

@komape thank you for reporting this and for proposing to send a PR.

The Vert.x 5 release is expected before the end of this year. The sooner the better :-)

@tsegismont tsegismont added this to the 5.0.0 milestone Oct 28, 2024
@komape
Copy link
Contributor Author

komape commented Oct 28, 2024

@tsegismont I took a look but unfortunately I cannot execute the RouterTest due to the error further below.

I guess this issue is not the right place to ask for help but I'm not sure where else I should ask. I couldn't find anything in the community/user group. I requested to join in order to ask for help. I also couldn't find anything in the commiters group and I cannot ask to join the group. Can you add me? The link to the development group is not working at all anymore. The gitter channel is full with spam and also not usable. I also thought about Stack Overflow but it states at multiple places that the other channels are preferred.

Which is the right place to ask for help regarding this issue? I cannot test my added code at the moment which I would like to do before I open a PR. Thanks for your help in advance!

Starting test: RouterTest#testConsumes 
Unhandled exception 
java.lang.NoClassDefFoundError: io/vertx/ext/auth/audit/SecurityAudit
	at java.base/java.lang.Class.getDeclaredFields0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredFields(Class.java:3473)
	at java.base/java.lang.Class.getDeclaredField(Class.java:2780)
	at java.base/java.util.concurrent.atomic.AtomicIntegerFieldUpdater$AtomicIntegerFieldUpdaterImpl$1.run(AtomicIntegerFieldUpdater.java:398)
	at java.base/java.util.concurrent.atomic.AtomicIntegerFieldUpdater$AtomicIntegerFieldUpdaterImpl$1.run(AtomicIntegerFieldUpdater.java:396)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:571)
	at java.base/java.util.concurrent.atomic.AtomicIntegerFieldUpdater$AtomicIntegerFieldUpdaterImpl.<init>(AtomicIntegerFieldUpdater.java:395)
	at java.base/java.util.concurrent.atomic.AtomicIntegerFieldUpdater.newUpdater(AtomicIntegerFieldUpdater.java:93)
	at [email protected]/io.vertx.ext.web.impl.RoutingContextImplBase.<clinit>(RoutingContextImplBase.java:43)
	at [email protected]/io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:68)
	at [email protected]/io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:37)
	at [email protected]/io.vertx.core.http.impl.Http1xServerRequestHandler.handle(Http1xServerRequestHandler.java:72)
	at [email protected]/io.vertx.core.http.impl.Http1xServerRequestHandler.handle(Http1xServerRequestHandler.java:31)
	at [email protected]/io.vertx.core.impl.ContextBase.emit(ContextBase.java:83)
	at [email protected]/io.vertx.core.http.impl.Http1xServerConnection.handleMessage(Http1xServerConnection.java:164)
	at [email protected]/io.vertx.core.net.impl.VertxConnection.read(VertxConnection.java:240)
	at [email protected]/io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:147)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at [email protected]/io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)
	at [email protected]/io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensionHandler.onHttpRequestChannelRead(WebSocketServerExtensionHandler.java:158)
	at [email protected]/io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensionHandler.channelRead(WebSocketServerExtensionHandler.java:82)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at [email protected]/io.vertx.core.http.impl.Http1xUpgradeToH2CHandler.channelRead(Http1xUpgradeToH2CHandler.java:120)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at [email protected]/io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346)
	at [email protected]/io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at [email protected]/io.vertx.core.http.impl.Http1xOrH2CHandler.end(Http1xOrH2CHandler.java:61)
	at [email protected]/io.vertx.core.http.impl.Http1xOrH2CHandler.channelRead(Http1xOrH2CHandler.java:38)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at [email protected]/io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1357)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
	at [email protected]/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at [email protected]/io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:868)
	at [email protected]/io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
	at [email protected]/io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.handle(AbstractNioChannel.java:444)
	at [email protected]/io.netty.channel.nio.NioIoHandler$DefaultNioRegistration.handle(NioIoHandler.java:386)
	at [email protected]/io.netty.channel.nio.NioIoHandler.processSelectedKey(NioIoHandler.java:585)
	at [email protected]/io.netty.channel.nio.NioIoHandler.processSelectedKeysOptimized(NioIoHandler.java:560)
	at [email protected]/io.netty.channel.nio.NioIoHandler.processSelectedKeys(NioIoHandler.java:501)
	at [email protected]/io.netty.channel.nio.NioIoHandler.run(NioIoHandler.java:478)
	at [email protected]/io.netty.channel.SingleThreadIoEventLoop.runIo(SingleThreadIoEventLoop.java:184)
	at [email protected]/io.netty.channel.SingleThreadIoEventLoop.run(SingleThreadIoEventLoop.java:156)
	at [email protected]/io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:1123)
	at [email protected]/io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at [email protected]/io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.ClassNotFoundException: io.vertx.ext.auth.audit.SecurityAudit
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
	... 57 more

@tsegismont
Copy link
Contributor

It's surprising, the Vert.x user and dev groups are supposed to be open to any email sender. Are you aware of any restriction @vietj ?

@komape please create a draft PR to share your code and I'll give it a try. Thanks

komape added a commit to komape/vertx-web that referenced this issue Oct 30, 2024
@komape komape linked a pull request Oct 30, 2024 that will close this issue
@komape
Copy link
Contributor Author

komape commented Oct 30, 2024

@tsegismont Thanks, see PR #2672 for the draft.

komape added a commit to komape/vertx-web that referenced this issue Oct 30, 2024
komape added a commit to komape/vertx-web that referenced this issue Oct 30, 2024
komape added a commit to komape/vertx-web that referenced this issue Oct 30, 2024
komape added a commit to komape/vertx-web that referenced this issue Oct 30, 2024
@tsegismont tsegismont self-assigned this Nov 7, 2024
@tsegismont tsegismont changed the title Add Accept header to 415 reponses Add Accept header to 415 responses Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants