Simple web server using bash and nc
gist.github.com
gist.github.com
mkfifo buffer; while true; do cat buffer | nc -lp 80 | tee -a client.txt | nc domain.com 80 | tee buffer >> server.txt ; done
Useful to analyze whats going on between the browser and the server. After running the oneliner, you can connect to domain.com via 127.0.0.1 and all data sent from your client will be logged in client.txt and all data received from the server will be logged in server.txt
In Firefox, you have to set network.http.max-connections to one, so Firefox only sends one request at a time. This proxy can only handle one simultaneous connection :)
thinking out loud:
This might be a great tool for certain end to end test scenarios as the script could easily be templatized in order to pipe through sed to select difference binary responses ... and be checked in to have a immutable point-in-time version of the test response.
(edit: ps: I love single file pieces of code like this -- I once wrote a boot loader and "mini-os" in a single file for an embedded board. When I started telling people about it they loved it because they could literally read through the code like a word document and learn how I got it all to work)
{ echo -ne "HTTP/1.0 200 OK\r\nContent-Length: $(wc -c <some.file)\r\n\r\n"; cat some.file; } | nc -l -p 8080
https://en.wikipedia.org/wiki/Netcathttps://github.com/jneen/balls
I just love the name :)
Discussion https://news.ycombinator.com/item?id=2781019
python2 -m SimpleHTTPServer
or python3 -m http.serverTo make it more portable a wrapper function which uses whatever is available would be appropriate.