square / okhttp

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.
https://square.github.io/okhttp/
Apache License 2.0
45.72k stars 9.15k forks source link

Support Websockets over HTTP/2 #3918

Open yschimke opened 6 years ago

yschimke commented 6 years ago

https://tools.ietf.org/html/draft-ietf-httpbis-h2-websockets-00

Bootstrapping WebSockets with HTTP/2 draft-ietf-httpbis-h2-websockets-00

Abstract

This document defines a mechanism for running the WebSocket Protocol [RFC6455] over a single stream of an HTTP/2 connection.

JakeWharton commented 6 years ago

Been following this from the HYBI mailing list. I wish they'd address more of the design flaws of the protocol as part of this.

yschimke commented 6 years ago

Is the idea you use existing connections you probably have (e.g. webbrowser opened when getting HTML + JS). Just curious for service usage, are you meant to try HTTP/2, see if supported then re-establish with HTTP/1.1 if not?

JakeWharton commented 6 years ago

I haven't been paying that close attention so I'm not sure. Mostly just interested in it because web sockets are giant inefficient balls of terrible with the XOR-ing of bytes and the need for a dedicated connection. This at least aims to solve the second problem.

yschimke commented 6 years ago

On second thought I think that's what I like about the spec. It isn't actually anything specific to websockets, it's just socket (bidirectional streams) over HTTP/2. ALPN over HTTP/2.

They just chose this registry https://www.iana.org/assignments/http-upgrade-tokens/http-upgrade-tokens.xhtml

over this one https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids

Great way to get secure tunnels supported in an almost undetectable and unstoppable way. Great for the dissidents of the world.

yschimke commented 6 years ago

Implementation wise, generalising RealWebSocket.Streams looks really doable.

crossle commented 6 years ago

When support?

yschimke commented 6 years ago

Very early PR is here, but I haven't started on HTTP/2 parts yet, just refactoring with HTTP/1.1. It's not my day job, but I hope I'll have a chance to push forward on it in next week or so.

Realistically it won't be in 3.11, so maybe experimental support in 3.12 is more likely.

yschimke commented 6 years ago

@crossle do you know any servers that already support this?

crossle commented 6 years ago

@yschimke Sorry, before we developing server use WS over HTTP/2, but okhttp not support, so we switch to HTTP/1.1, 😅

mostroverkhov commented 4 years ago

libwebsockets supports rfc8441 so websockets-over-http2 becomes viable option if primary clients are native mobile. I have netty based impl of both server and client https://github.com/jauntsdn/netty-websocket-http2 that should work on android without much modifications, though It would be nice to have client implemented here given okhttp is dependency of every mobile project.

yschimke commented 3 years ago

https://www.chromestatus.com/feature/6251293127475200

Status in Chromium

Blink components: Internals>Network>HTTP2

Enabled by default (tracking bug) in:

Chrome for desktop release 91
Chrome for Android release 91
Android WebView release 91
yschimke commented 1 year ago

Unless anyone is moving on this, I'll likely take a look over the christmas period.