Created
May 2, 2017 21:45
-
-
Save davidblitz/574a7f9e3ea827ccad5621d3db2a94c9 to your computer and use it in GitHub Desktop.
Minimal Webserver in bash using netcat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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