gnarroway / hato

An HTTP client for Clojure, wrapping JDK 11's HttpClient
MIT License
380 stars 27 forks source link

HTTP/2 is default for non-TLS connections #63

Closed dancek closed 1 year ago

dancek commented 1 year ago

For plain-http (non-TLS) requests to a server only supporting HTTP/1.1, hato.client seems to default to HTTP/2 but fail to fallback, yielding a HTTP 400 response that's hard to debug.

This may be specific to the server, but at a glance it seems like the fallback mechanism probably uses ALPN which requires TLS.

Since basically nobody does unencrypted HTTP/2, maybe the default for unencrypted connections should be HTTP/1.1?

dancek commented 1 year ago

If this sounds reasonable I could make a PR.

gnarroway commented 1 year ago

Thanks for raising this. Could you please maybe do a draft PR with a failing test reproducing the issue first?

dancek commented 1 year ago

I'm still planning to do this but I've been a bit too busy with other coding. I'll try to find time tomorrow.

dancek commented 1 year ago

Now that I tried writing a proper test case and experimented with a couple of different HTTP servers, I realize the server I was connecting to was misbehaving. Since the Upgrade: h2c mechanism always actually starts with HTTP/1.1, any server that doesn't support HTTP/2 won't be upgraded and there's no issue. In my case I guess the server does upgrade to HTTP/2 but then fails to process the request for one reason or another.

dancek commented 1 year ago

Sorry for the misdiagnosis! I'll be closing this issue.

I'll still make a tiny PR to fix a currently failing unit test.