Last active
August 6, 2021 22:03
-
-
Save CMCDragonkai/87bf53c3f93ef5dcb7e4 to your computer and use it in GitHub Desktop.
Socat Simple HTTP Server #cli #network
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
socat \ | |
-v -d -d \ | |
TCP-LISTEN:1234,crlf,reuseaddr,fork \ | |
SYSTEM:" | |
echo HTTP/1.1 200 OK; | |
echo Content-Type\: text/plain; | |
echo; | |
echo \"Server: \$SOCAT_SOCKADDR:\$SOCAT_SOCKPORT\"; | |
echo \"Client: \$SOCAT_PEERADDR:\$SOCAT_PEERPORT\"; | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This server still has a problem. It doesn't say that it will close the connection which it should with
Connection: close
header.Furthermore, if we do that, we need to actually send back the terminating characters.
Here is an example:
socat -T 1 -d -d TCP-L:10081,reuseaddr,fork,crlf SYSTEM:"echo -e \"\\\"HTTP/1.0 200 OK\\\nDocumentType: text/plain\\\n\\\ndate: \$\(date\)\\\nserver:\$SOCAT_SOCKADDR:\$SOCAT_SOCK‐ PORT\\\nclient: \$SOCAT_PEERADDR:\$SOCAT_PEERPORT\\\n\\\"\"; cat; echo -e \"\\\"\\\n\\\"\""