Fork me on GitHub
#clojure
<
2019-09-27
>
wei03:09:58

what's a good way to consume everything currently in an input stream and return a string, while leaving the input stream open?

andy.fingerhut04:09:26

The Java Reader class has a ready method that returns true if the next read of a single character is guaranteed not to block. You could call that in a loop, append'ing characters read to a StringBuilder, and when ready returns false, call toString on the StringBuilder: https://docs.oracle.com/javase/8/docs/api/java/io/Reader.html#ready-- https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html#append-char-

👍 4
micahasmith14:09:36

hi wonderful clojure people,,, i was wondering, what version of java do you use locally and in live when you deploy? having a debate internally about all this

micahasmith14:09:52

for example, do we feel openjdk 11's TLS support doesnt generally inhibit dev

ghadi14:09:00

Consistency between dev and deployed is more important that which version

ghadi14:09:49

If you are preparing for an upgrade you probably have to juggle multiple versions

micahasmith14:09:18

what are you using @ghadi?

ghadi14:09:03

It varies by project. 8 or 11 for production purposes. Develop against 13 & trunk for work on Clojure itself

dharrigan14:09:04

I deploy using 11.

dharrigan14:09:14

actually, same as Ghadi 🙂

dharrigan14:09:57

We've migrated all our services to Java 11 where fesible.

micahasmith14:09:26

were the ones where it wasnt possible based on internal or external factors to your codebase?

ghadi14:09:58

As in, dependencies?

micahasmith14:09:00

for instance, we had one service where we couldn't go to 11 based on a http clojar we were using not being up to speed with openjdk 11 tls

dharrigan14:09:43

external, some things we're not touching as we're considering rewriting...and some things have dependencies that are so old that we thought - best leave alone for now, and rewrite later...perhaps 🙂

dharrigan14:09:03

but in principle all new code targets 11.

dharrigan14:09:26

we those, like moiself, on 13 as we like to live at the edge 🙂

micahasmith14:09:57

found a prev convo on this from august t7th

case15:09:38

Possibly impossible question, does anyone know off-hand how to grab the remote address of a get request in aleph? I've been reading all morning and can't seem to find a sane way to do this, the idea would be to have it returned in the response map. I'm open to using a different library as well.

denik15:09:07

@case sounds like the GET url is something your program would have to know about to make the request. You could just merge it into the response, right?

case16:09:42

@denik sorry, my question wasn't formed very well. I want the final ipv4/v6 of the request. I have the URL, yes, but I don't want to sideband another DNS resolution to get the A record, which may not be the final one, since there could be a redirect on the HTTP server there.

seancorfield16:09:21

@case In Ring, there's :remote-addr but if you're behind a load balancer, you may need to check headers, such as X-Forwarded-For. I suspect that depends on the HTTP server adapter in use, so I don't know if that's any help with aleph...

💯 4
case17:09:57

Thanks @seancorfield, this is also for a client request, not a server accepting a connection.

seancorfield17:09:33

Ah, so you want to resolve the domain name used in a get back to an IP address?

case17:09:39

Correct, that would be ideal. I know Netty is doing it behind the scenes, just no clear way to propagate the value.

seancorfield17:09:15

@case And this approach is not suitable?

user=> (map #(.getHostAddress %) (java.net.InetAddress/getAllByName ""))
("204.79.197.200" "13.107.21.200" "2620:1ec:c11:0:0:0:0:200")
user=> 

👍 4
seancorfield17:09:24

(the JVM caches DNS resolution, I believe, so if you've already reached out to a server via its domain name, the above should be low cost?)

case17:09:44

I wasn't aware of the DNS cache! That's awesome, that's the main reason I wrote a solution like that off above. I'll keep looking for a middle-ware path and use that as an alternate. Thanks!