Skip to content

Instantly share code, notes, and snippets.

@davidblitz
Created May 2, 2017 21:45
Show Gist options
  • Save davidblitz/574a7f9e3ea827ccad5621d3db2a94c9 to your computer and use it in GitHub Desktop.
Save davidblitz/574a7f9e3ea827ccad5621d3db2a94c9 to your computer and use it in GitHub Desktop.
Minimal Webserver in bash using netcat
#!/bin/bash
while $true
do
{ echo -ne "HTTP/1.0 200 OK\r\nContent-Length: $(wc -c <"$1")\r\n\r\n"; cat "$1"; } | nc -l 8080
#echo -n -> do not output the trailing newline
#echo -e -> enable interpretation of backslash escape
#nc -l -> listen for an incoming connection instead of initiating one
#IS IT POSSIBLE TO SEND A WRONG HTTP REQUEST TO PORT 8080 AND STILL GET THE STANDARD RESPONSE?
#-->test with curl!
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment