I'm looking at babashka.http-client for extending it with support for *_proxy environment variables. I'd love to support no_proxy and both http and https proxies, but it seems like java.net.Proxy is not included in babashka/SCI(?). I guess the simplest way here would be to just use one of the variables here for a single proxy, because adding the java.net.Proxy class to babashka would have negligible benefit. Does that make sense?
I'm currently working on http-client, would something like
(make-proxy-selector [[<pred> <proxy-config>] [<pred> <proxy-config>])
be considered idiomatic? For pred, I'd write some combinator functions like this:
(defn proxy-scheme [scheme proxy-config]
[(fn [^URI uri] (= (.getScheme uri) scheme)) (->Proxy proxy-config)])
(defn exclude-urls [excluded-urls]
[(fn [^URI uri] (some (fn [excluded-url] (str/ends-with? (.getHost uri) excluded-url)))) java.net.Proxy/NO_PROXY])
don't know, I'd have to look into this. how do other libs do this like hato, clj-http etc?
I'll have a look, thanks for the pointers!
I've opened a https://github.com/babashka/http-client/pull/81 containing my first stab at an implementation. It also contains some default proxy functionality that I haven't tested yet, I can rip that out and implement that separately.
(feel free to unleash devastating feedback, this has been quite fun in itself).
Can you lay out the interop that is necessary to do what you want? Then we should enable that in babashka + also adding idiomatic Clojure support to babashka.http-client
I think it would just be having the java.net.Proxy class available, then I would do something like
(defn get-default-proxy []
...
(proxy [ProxySelector] []
(select [uri]
(cond
(= no-proxy :all) Proxy/NO_PROXY
(contains no-proxy-list (str uri)) Proxy/NO_PROXY
(= (.getScheme uri) "https") (Proxy. Proxy$Type/HTTP <proxy-constructed-from "https_proxy")
(= (.getScheme uri) "http") (Proxy. ...))))))
Just for the default proxy behavior implementation, this is probably what it'd look like.so you also need ProxySelector then right
That's already in
then it makes even more sense to just add http://java.net.Proxy
I'll look into building a person bb that has the classes, I remember seeing some documentation for that.
the class can be added to src/babashka/impl/classes.clj but we need some interop tests around this in babashka.interop-test to be tested with the native. just writing a Github issue is ok too
probably you will have to add Proxy$Type separately too
Huh, I'm tryng to build babashka from source, but the uberjar script gets to the reflection step (`lein with-profiles …,+reflection do run` ) and just hangs. Strange.
did you clone the submodules too? this is a common mistake people forget
yep, forgot it before, did it correctly, but it still hangs. Strange.
are you running with a graalvm jvm?
Huh, now it seems to work. Great.
Thanks for the help nonetheless!
ok :)
There's a https://github.com/babashka/babashka/pull/1970, I hope this is somewhat useful.
looks good!
Awesome! I'll write some code for http-client later this week.
great, thanks
Hey, is there still something missing in the http-client PR for more complicated proxy routing?
I hope to look at this soon again. currently focusing on different parts of bb libs :) Also, not high priority since we can do it using Java interop already, right?
No problem! Yeah, I think so re. Java interop, but I also have the "default proxy" functionality in the pipe somewhere.
👍 let me make a note to look at this before I publish a new bb
currently I'm knee-deep in bb.cli new features
new rlz! https://clojurians.slack.com/archives/C06MAR553/p1776692645742509
oh no, even includes my spelling mistakes 😛
I thought I fixed those? ;)
Ah, it's only in this message. Thanks for the spelling correction.
Hi, is it possible that java.util.concurrent.locks.ReentrantLock used to be part of the classes usable from babashka and were removed? I am running some code I haven't run in a while and I am having trouble with that class (`Unable to resolve classname` error).
$ bb -e 'java.util.concurrent.locks.ReentrantLock'
java.util.concurrent.locks.ReentrantLockstill part of bb
I must be doing something wrong then. Thanks!
check the version of your bb
babashka v1.12.199
that's old
that's what homebrew on linux got me...
maybe update your homebrew repo
ReentrantLock was added in .200
ok thx I really must have messed up something with homebrew.
my bad I am an idiot... I have mise messing things up... bb must be installed twice I updating the brew won't fix my issue.
no problem
Thanks again.
its fixed!
Hi, a question about the nREPL implementation of Babashka. I am doing something... weird (like always hehehe) and I would like to share if it's the "right way" of doing that (whatever that might mean in the context)
Basically, I am running Babashka's nREPL manually - it's a .bb file that runs nrepl/start-server!. This is used to spin up docker, manually, and then tail for logs; I'm using babashka.process to tail for the logs, and then capture the stdout and stderr into a string and printing it.
Because these things run in parallel, I am having some situations where the bencode from nREPL is getting interleaved - essentially, supposing a code I do returns :ok, and it prints on the screen hello. This in nREPL would be an {"out" "hello"} message (`d3:out5:helloe` in bencode) and a eval result {"value" ":ok"} message (`d5:value3::oke` in bencode). In this specific case, I am getting something like dd3:5:valueout....
Now, what should the "right way" of doing this in a way that doesn't interfere with nREPL? The code of what I am doing right now is this one: https://gitlab.com/mauricioszabo/see-ya/-/blob/rewrite-without-vibe-coding/src/see_ya/executor.clj?ref_type=heads#L57-88, nothing too crazy here, except that I do a (.flush io) (which I believe is where it causes the problem, but it helps a lot with the output because I have multiple cases where the output is never printed until the command exists, which sometimes do take a while).
Let me see if I understand the problem... the bencode from nREPL is interleaved?
oh I see
I think the bencode writer should be serialized using locking or so
such that they can't be interleaved
let me push a fix so you can use the development version
Amazing, thanks 🙂. I'll check it as soon as you push the fix (hopefully I can also reproduce the problem, it's hard to reliably reproduce it...)
pushed fix. wait for 10 mins and then install the dev build with:
bash <(curl ) --dev-build --dir /tmp Just a heads up... I am still looking at this error. Because the interleave happens with async code, it's hard to reliably reproduce... and suddenly, I can't anymore facepalm. So I'm starting to implement a part of the code that's completely parallel, to check if I can reproduce the error again, and as soon as I can I'll test with this dev build 🙂
I have a test which reproduces this
And it works, thanks! The error I was experiencing on my side is also fixed 👍