5 ms·
Unneccessary $() fork, unnecessary cat, and at best a bit thoughtless to expand the file's contents onto a commandline just to squirt it. Sorry buddy, but, do n
by Brian_K_White 4y ago
Unneccessary $() fork, unnecessary cat, and at best a bit thoughtless to expand the file's contents onto a commandline just to squirt it. Sorry buddy, but, do not be proud of this.
[edit I should not simply say that without showing what is supposedly the better way]
no large cmdline, allow cat
while : ;do { printf 'HTTP/1.1 200 OK\n\n' ;cat index.html ; } | nc -N -l $PORT ;done
no cat, allow large cmdline
while : ;do IFS= read -d '' -r x < index.html ;printf 'HTTP/1.1 200
OK\n\n%s' "$x" | nc -N -l $PORT ;done
no cat, no large cmdline (though not strictly enforced)
while : ;do { printf 'HTTP/1.1 200 OK\n\n' ;while read -r x ;do printf '%s' "$x" ;done <index.html ; } | nc -N -l $PORT ;done
There are several versions of nc, mine uses -N to exit on eof.
From here it's only a little more to read -n 4096 to read in 4k chunks instead of in lines, since a valid html document could actually be all on one line of arbitrary unlimited length, and the final version above would be no different from the "allow large cmdline" version.
- gammalost 4y ago> Sorry buddy, but, do not be proud of this A bit patronizing. It's just a fun and simple project. Not something to be all serious about
- chalst 4y ago> Sorry buddy, but, do not be proud of this. This is 'Show HN', not code review. You are being excessively negative.
- kubafu 4y agoThe tone of your comment is not nice. And if you went all the way to suggest improvements, you could have sent a PR already.
- tux2bsd 4y ago> Sorry buddy, but, do not be proud of this. You are a plonker.
- trhoad 4y ago