Live data from Hacker News

TIL: You can make HTTP requests without curl using Bash /dev/TCP

mareksuppa.com

151–160 of 255 posts

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#153
post #19

Earlier quoted context omitted.

It seems pretty cool, but I am wondering if there's any drawback on just using images that support curl? I can't think of any and to me it's kinda a must have, even on production images

More than one ~500 employee company I've worked at has had security policies either encouraging or requiring the use of "distro-less" images - images with no OS components other than the absolute minimum required to run the application. For go binaries this meant literally nothing in the container apart from the executable. In theory it has a couple of benefits. You don't have to re-deploy your image to patch CVE's i…

> not having standard debugging tools available where and when we need them

Keeping in mind that containers are merely a bunch of namespaces, there's nothing stopping you from entering the same PID namespace with a different mount namespace in order to debug.

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#154

Earlier quoted context omitted.

perhaps you meant "in previous millennium" ?

If someone referred to the "previous decade" in 2004, would you have said the same thing? As the calendar rolled from 1999 to 2000, we entered a new millennium, century, decade, year, day, ...

Yes, absolutely. I use the largest interval any time I can get away with it!

Every Jan 2 I start saying "last year" and every Dec I say "see you next year"

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#155
post #79
post #12

Earlier quoted context omitted.

> No, it can not. Bash lets you open TCP sockets. Very fair pushback -- I did get carried away and will update the article to be more precise. Thanks for raising it! > For less insane, non-bash shells there is always nc which is usually probably the wiser choice. For completeness, `nc` or any netcat equvialent I could think of was not available in the image I was trying this with. It would certainly be a better optio…

FWIW, I didn't read this as AI-like. Even on a re-read, it's only the quasi-em-dash, and _maybe_ the polite acknowledgement of "Very fair pushback" (just good etiquette, IMO!) that would ring any alarm bells. You're fine.

Not to mention, the typo in the word "equivalent".

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#156
post #76

> As it turns out, bash can speak HTTP by itself. No, it can not. Bash lets you open TCP sockets. What you are doing here is trying to speak HTTP yourself, which is fine for testing and debugging, and hella cool for fun to do by hand, but you will shoot yourself in the foot if you try to use this pseudo http client unattended in reality. This toy code does not parse HTTP properly and will break. You could of course w…

Need to be clear that "full http server in pure bash" is incorrect. Bash cannot listen on a TCP/UDP socket for incoming connections. bash-web-server project builds a C language socket listener [0] that is dynamically loaded at run-time as a "built-in" module that makes the functionality available. [0] https://github.com/bahamas10/bash-web-server/tree/main/loada...

By this logic, Linux does not support Wi-Fi, because all the driver modules are "dynamically loaded at run-time."

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#157
post #2

I ran into this while checking connectivity between containers on an internal Docker network where the image had neither curl nor wget. The main surprise was that Bash has /dev/tcp which lets you do the equivalent of an HTTP request with a bit of shell magic, for instance: exec 3 /dev/tcp/service/8642 printf 'GET /health HTTP/1.1\r\nHost: service\r\nConnection: close\r\n\r\n' >&3 cat Where `service` is just the hostn…

It seems pretty cool, but I am wondering if there's any drawback on just using images that support curl? I can't think of any and to me it's kinda a must have, even on production images

It’s handy when you’re troubleshooting issue on a running container which you can’t just rebuild the image and reload

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#158

Earlier quoted context omitted.

Because curl is not installed in minimal docker images.

neither is bash or even sh for that matter :) if you have bash, you probably have apk or apt

Sometimes I worked in environment that blocks all internet access, but I still need some way to test internal connectivity.

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#159

Earlier quoted context omitted.

If someone referred to the "previous decade" in 2004, would you have said the same thing? As the calendar rolled from 1999 to 2000, we entered a new millennium, century, decade, year, day, ...

Yes, absolutely. I use the largest interval any time I can get away with it! Every Jan 2 I start saying "last year" and every Dec I say "see you next year"

Just following alignment rules right?

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#160

Earlier quoted context omitted.

perhaps you meant "in previous millennium" ?

If someone referred to the "previous decade" in 2004, would you have said the same thing? As the calendar rolled from 1999 to 2000, we entered a new millennium, century, decade, year, day, ...

when you compare tech from 1999 and today, it does feel like new millennium tbh
Post reply on HN