Notices where this attachment appears
-
@Zerglingman @Pawlicker @amerika @kirby @mint
> Write a webserver using (mostly) just sed and awk? 👀
http://werc.cat-v.org/docs/web-server-setup/rc-httpd
Or if you want it to just be awk:
listen1 'tcp!*!9090' awk 'BEGIN{RS=ORS="\r\n"} NR==1{method = $1; path = $2} NF==0{if(method != "GET"){print "HTTP/1.0 501 Not Implemented";print "";exit} print "HTTP/1.0 200 OK"; print "Content-Type: text/plain"; print "Server: HARE/0.1 (HTTP Awk Retard Echo-er)"; print ""; print path;exit}'
(If you don't have listen1, you can use netcat or inetd or whatever.)
Run that, and you can point a browser at http://localhost:9090/whatever and it will echo it back to you. It should be pretty easy to tell how to use system() or getline in awk to dispatch to different programs or pieces of code based on what path is requested.
You are not going to have a good time building that kind of thing in awk, overall. You can have a screwdriver and a hammer and a saw, or you can have some kind of unholy multitool that is no good for any given task but can sorta do all of them.