-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
AbstractHandshakeHandler should support RFC 8441 WebSocket upgrade via CONNECT with HTTP/2 #34044
Comments
@jazdw As far as I understand the Servlet spec does not support CONNECT requests. Can you explain what kind of support you're asking here? |
I'm asking for Spring to support RFC 8441 WebSocket upgrades. I noticed that out of the box on Jetty 12 EE 10 the WebSocket upgrades didn't work so I opened an issue. Here's a link to the relevant section of the Servlet spec - https://github.com/markt-asf/servlet-api/blob/master/spec/src/main/asciidoc/servlet-spec-body.adoc#213-additional-methods
From reading that, I don't think the statement "the Servlet spec does not support CONNECT requests" is true. It looks like it is up to the container implementation. |
Can we take a step back? Indeed, Servlet containers can support other HTTP methods. Spring is using Servlet containers but isn't one itself. Our standard websocket upgrade is using a standard Servlet which won't support connect requests, hence my comment. Maybe something can be done at Servlet container configuration level in Spring Boot? |
I am not using Spring Boot, this is a Jetty webserver + Spring MVC. I could create a project to reproduce this issue but I don't have time right at the moment.
Agreed. I am using the Jetty webserver and Jetty servlet container, both of which do seem to support CONNECT.
It doesn't? Which servlet are we talking about here? The dispatcher servlet? Maybe I am misunderstanding something that will become more clear if I try and create a reproduction project. The application I am working on is pretty massive and confusing the follow. To be clear though, I observed the CONNECT request making its way through to AbstractHandshakeHandler L172 from the above snippet.
Not Spring boot, but yeah you can definitely address this if you are using Jetty by setting |
@jazdw thanks a lot for your feedback. We would like to support this case and we'll look into reproducing this. |
The default implementation of HttpServlet that all servlets, including DispatcherServlet, extends from doesn't handle CONNECT. It you could break at |
As requested, the line numbers are from Spring 6.2.2 so a little different to above. It looks like the
|
Thanks for that. Indeed the We can make a targeted change in |
@rstoyanchev I just tested this out on 6.2.3-20250203.154249-25 and unfortunately there's an issue. You are checking for equality of the f477c16#diff-113f56c6d87cc3c535d4cddb10c55d4ce8f1e358a21072be082ad3cbecdeac46R218 |
Further changes are actually required, but I do have it working. I will open a PR. |
Superseded by #34362. |
If the web server advertises that it supports RFC 8441 via the HTTP/2
SETTINGS_ENABLE_CONNECT_PROTOCOL
parameter then some web browsers (Chrome, Firefox) will follow RFC 8441 to open a WebSocket over a HTTP/2 stream using theCONNECT
HTTP method.The
org.springframework.web.socket.server.support.AbstractHandshakeHandler#doHandshake
method however only supports theGET
method and will respond with405 Method Not Allowed.
and log an error message:Handshake failed due to unexpected HTTP method: CONNECT
The work around is to disable RFC 8441 in your web server, e.g. with Jetty you can set
org.eclipse.jetty.http2.server.AbstractHTTP2ServerConnectionFactory#setConnectProtocolEnabled
to false (the default is that it is enabled in Jetty 12 EE10).This problem was observed in Spring 6.2.0.
spring-framework/spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java
Lines 172 to 179 in f8fd6da
The text was updated successfully, but these errors were encountered: