Many people here fail to realize, this is an <i>excellent</i> debugging server. I used to have a server to print out the body and headers of requests when building an api to make sure things were going (the right headers and request body) out as expected <a href="https://github.com/minhajuddin/httpdebug/blob/master/app.go" rel="nofollow">https://github.com/minhajuddin/httpdebug/blob/master/app.go</a>.<p>This is a much lighter and nicer version. This is going into my ~/bin/httpdebug :)<p>You can try sending a few curl requests to see that this really prints the headers and body.<p><pre><code> curl -H "api-key: Foo" -X POST --form name=Khaja http://localhost:8080/</code></pre>
I think the point here is to demonstrate that one might think that web servers are mystical beasts (true) but after all, they "just" return a HTTP header and some content.
Bash (shell-script) is a very powerful language, but a bit too complicated for the non-programmer (computer hacker). Then we got Perl, but it is also a bit too complicated. Now we have JavaScript doing the same thing, but also JavaScript (ES6) is now getting more complicated. I wonder is there a rule that says a (scripting) language for non-programmers will eventually either die or end up being too complicated for non-programmers ?
This reminds me a lot of Certbot's use of the Python SimpleHTTPServer:<p><pre><code> $(command -v python2 || command -v python2.7 || command -v python2.6) -c
"import BaseHTTPServer, SimpleHTTPServer;
s = BaseHTTPServer.HTTPServer(('', {port}), SimpleHTTPServer.SimpleHTTPRequestHandler);
s.serve_forever()"</code></pre>
I had to look up the colon minus syntax, here's the answer
<a href="http://stackoverflow.com/questions/10390406/usage-of-in-bash" rel="nofollow">http://stackoverflow.com/questions/10390406/usage-of-in-bash</a>
While googling for this, found a "Big list of http static servers": <a href="https://gist.github.com/willurd/5720255" rel="nofollow">https://gist.github.com/willurd/5720255</a><p>Not that big.
not to be that guy, but that's<p>1. hardly a web server<p>2. hardly pure bash<p>of course writing a server of anything in pure bash is a tad bit difficult, as opposed to a client - bash can connect(), but can't bind() / listen() nor accept() unless, of course, you use something to expose these syscalls, but that opens a whole another can of worms...