Open seowalex opened 3 days ago
Try it with vanilla java.net.http
as well. If it happens there as well, it's probably not an issue with bb.http-client and vice versa. Also try it with JVM vs bb (not sure if you're using bb).
I tried using vanilla java.net.http
and it seems to error as well:
#!/usr/bin/env bb
(-> java.net.http.HttpClient
.newHttpClient
(.send (-> java.net.http.HttpRequest
(.newBuilder (java.net.URI.
"http://uptime-kuma/api/push/XXXXXXXXXX"))
.build)
(.ofString java.net.http.HttpResponse$BodyHandlers))
prn)
#object[jdk.internal.net.http.HttpResponseImpl 0xc7af3f7 "(GET http://uptime-kuma/api/push/XXXXXXXXXX) 502"]
I suppose the next step is to try with Java itself.
I tried it with Java 21, and it returns the same error, so looks like this is a Java problem.
Edit: Setting some debug flags shows the headers sent, which reveals the true cause:
GET /api/push/XXXXXXXXXX HTTP/1.1
Connection: Upgrade, HTTP2-Settings
Host: uptime-kuma
HTTP2-Settings: AAEAAEAAAAIAAAABAAMAAABkAAQBAAAAAAUAAEAA
Upgrade: h2c
User-Agent: Java-http-client/21.0.3
Looks like by default it is trying to upgrade to HTTP/2, which Uptime Kuma is apparently not very happy about (causing it to send a 502 Error).
While this default [mimics Java](https://docs.oracle.com/en/java/javase/21/docs/api/java.net.http/java/net/http/HttpClient.html#version()), it is surprising (at least to me) since curl
defaults to HTTP/1.1. Can I suggest adding the default to the docs?
Yes, PR welcome for doc change. Glad you found the issue.
I am attempting to make a GET request to Uptime Kuma (to make use of their push-based monitoring using a URL like http://uptime-kuma/api/push/XXXXXXXXXX). The service is proxied through Tailscale (in case it makes a difference). The following requests work:
babashka.curl
:org.httpkit.client
:However, trying to make the same request using
babashka.http
fails (it either hangs indefinitely or returns "Exceptional status code: 502"):Given that it only fails to work with
babashka.http-client
, it would seem like a bug in the library, but I don't seem to be able to figure out where the problem is. I am happy to provide any more information if needed.