java.net.ProtocolException: expected 0 bytes but received 8192
Hello. Long story short:
val url = "https://www.ozon.ru/"
val requestBuilder = Request.Builder().url(url)
requestBuilder.header("User-Agent", "Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.97 Mobile Safari/537.36")
val response = OkHttpClient.Builder().build().newCall(requestBuilder.get().build()).execute()
println(response.protocol)
println(response.header("Content-Length"))
println(response.headers)
println(response.body!!.contentLength())
println(response.body!!.contentType())
val body = response.body
val string = body!!.string()
body.close()
println(string)
h2 null 0 null Exception in thread "main" java.net.ProtocolException: expected 0 bytes but received 8192 at okhttp3.internal.connection.Exchange$ResponseBodySource.read(Exchange.kt:290) at okio.RealBufferedSource.select(RealBufferedSource.kt:229) at okhttp3.internal.Util.readBomAsCharset(Util.kt:265) at okhttp3.ResponseBody.string(ResponseBody.kt:187) at a.b.c.main(Hello.kt:377)
This site works when force Protocol.HTTP_1_1 in OkHttpClient builder, also works perfectly in browser with http2 (either from real device or from PC browser devtools with mobile UA).

To reproduce this error, you can use any mobile user-agent (I tried 3 different). Tried on OkHttp 4.10.0 / 5.0.0-alpha.10
Thanks, should be relatively easy to repro with a test server.
So it's sending an early hints (103).
Issue: https://github.com/square/okhttp/issues/3671 and a PR https://github.com/square/okhttp/pull/7196
Closing as a duplicate of https://github.com/square/okhttp/issues/3671