Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active August 6, 2021 22:03
Show Gist options
  • Save CMCDragonkai/87bf53c3f93ef5dcb7e4 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/87bf53c3f93ef5dcb7e4 to your computer and use it in GitHub Desktop.
Socat Simple HTTP Server #cli #network
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\";
"
@CMCDragonkai
Copy link
Author

CMCDragonkai commented Oct 30, 2018

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\\\"\""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment