From fffd213c8cba2135afda493d797c41c10354770e Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Sat, 12 Apr 2008 11:38:42 +0000 Subject: big svn cleanup --- src/Sockets/tests/sloppy_http.cpp | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/Sockets/tests/sloppy_http.cpp (limited to 'src/Sockets/tests/sloppy_http.cpp') diff --git a/src/Sockets/tests/sloppy_http.cpp b/src/Sockets/tests/sloppy_http.cpp new file mode 100644 index 0000000..9ea79c1 --- /dev/null +++ b/src/Sockets/tests/sloppy_http.cpp @@ -0,0 +1,55 @@ +#include +#include + + +class GetHttp : public TcpSocket +{ +public: + GetHttp(ISocketHandler& h, const char *request) : TcpSocket(h) + , m_request(request) {} + + void OnConnect() { + Send( m_request ); + } + + void OnRawData( const char *buf, size_t len ) { + if (len > 0) { + std::string tmp; + tmp.resize( len ); + memcpy( &tmp[0], buf, len ); + m_response += tmp; + } + } + + const std::string& Response() { + return m_response; + } + +private: + std::string m_request; + std::string m_response; +}; + + +std::string get_http(const char *host, int port, const char *request) +{ + SocketHandler h; + GetHttp sock(h, request); + sock.Open( host, port ); + h.Add(&sock); + while (h.GetCount()) { + h.Select(1, 0); + } + return sock.Response(); +} + + +int main(int argc, char *argv[]) +{ + std::string zz = get_http("www.alhem.net", 80, "GET /index.html HTTP/1.0\r\n" + "Host: www.alhem.net\r\n" + "\r\n"); + printf("%s\n%d\n", zz.c_str(), zz.size()); +} + + -- cgit v1.2.3