Java HTTP/2 Server Socket

可紊 提交于 2019-12-30 06:21:12

问题


I want to get server sockets working for HTTP/2 in Java, preferably TLS/https.

I've got a TLS server socket working fine, but browsers will only talk HTTP/1.1 to it. If I understand correctly, you need ALPN to get a HTTP/2 browser to connect to your TLS socket and start running HTTP/2 on it; browsers won't ask for upgrade to HTTP/2 on https. It seems Java8 does not do ALPN so far. Maybe there is some other way to coerce browsers to do HTTP/2, at least non-TLS.

So, anybody know how to make a Java server socket for HTTP/2?


回答1:


Java won't get ALPN until at least JDK 9, which is slated for late 2016 or 2017.

Meanwhile, you can use Jetty's ALPN implementation, or better yet, use Jetty (or other servers as suggested) directly rather than doing your own HTTP/2 implementation using ServerSocket.

[Disclaimer, I am a Jetty committer] Jetty 9.3 has great support for HTTP/2, including HTTP/2 Push.




回答2:


FYI, Java Dev Team is preparing ALPN for Java 9. Hopefully as you can see this issue, https://bugs.openjdk.java.net/browse/JDK-8062848,

ALPN support may be backported to JDK 8 so an implementation is needed that does not introduce any new Java SE APIs. This may require creating something in a com.oracle.ssl.net package or via System Properties.



来源:https://stackoverflow.com/questions/29399182/java-http-2-server-socket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!