Created
November 3, 2014 13:16
-
-
Save DaisukeTujita/249da1909040e985f808 to your computer and use it in GitHub Desktop.
WebService by gawk and bash. Please make response.txt include HTTP Responce Header.
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 : | |
do | |
echo "=== WebServer Start and Listen ===" | |
gawk 'BEGIN{ \ | |
SOCK="/inet/tcp/80/0/0"; \ | |
body_size=0; \ | |
#request head \ | |
while( (SOCK |& getline REQ) > 0){ \ | |
print REQ; \ | |
if( REQ~/^Content-Length/ ){ \ | |
split(REQ,cl,":"); \ | |
body_size=cl[2]; \ | |
} \ | |
if( REQ=="\r" ){ break; } \ | |
} \ | |
#request body \ | |
recive_size=0; \ | |
if(body_size > 0){ \ | |
while( (SOCK |& getline REQ) > 0){ \ | |
print REQ; \ | |
recive_size=recive_size + length(REQ) + 1; \ | |
if(recive_size >= body_size){ break; } \ | |
} \ | |
} \ | |
#response \ | |
RES_TXT="./response.txt"; \ | |
while( getline line < RES_TXT > 0){ \ | |
print line |& SOCK; \ | |
}\ | |
close(RES_TXT); \ | |
close(SOCK); \ | |
}' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment