fixed typo
[anytun.git] / Sockets / HttpDebugSocket.cpp
blob70bf75bf8bb990673134cb51ff385c04205383be
1 /** \file HttpDebugSocket.cpp
2 ** \date 2004-10-08
3 **/
4 /*
5 Copyright (C) 2004-2007 Anders Hedström (grymse@alhem.net)
7 This library is made available under the terms of the GNU GPL.
9 If you would like to use this library in a closed-source application,
10 a separate license agreement is available. For information about
11 the closed-source license agreement for the C++ sockets library,
12 please visit http://www.alhem.net/Sockets/license.html and/or
13 email license@alhem.net.
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License
17 as published by the Free Software Foundation; either version 2
18 of the License, or (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #ifdef _MSC_VER
30 #pragma warning(disable:4786)
31 #endif
32 #include "HttpDebugSocket.h"
33 #include "Utility.h"
34 #include "ISocketHandler.h"
37 #ifdef SOCKETS_NAMESPACE
38 namespace SOCKETS_NAMESPACE {
39 #endif
42 HttpDebugSocket::HttpDebugSocket(ISocketHandler& h) : HTTPSocket(h)
43 ,m_content_length(0)
44 ,m_read_ptr(0)
49 HttpDebugSocket::~HttpDebugSocket()
54 void HttpDebugSocket::Init()
56 if (GetParent() -> GetPort() == 443)
58 #ifdef HAVE_OPENSSL
59 EnableSSL();
60 #else
61 Handler().LogError(this, "url_this", -1, "SSL not available", LOG_LEVEL_WARNING);
62 #endif
67 void HttpDebugSocket::OnFirst()
69 Send(
70 "HTTP/1.1 200 OK\n"
71 "Content-type: text/html\n"
72 "Connection: close\n"
73 "Server: HttpDebugSocket/1.0\n"
74 "\n");
75 Send(
76 "<html><head><title>Echo Request</title></head>"
77 "<body><h3>Request Header</h3>");
78 Send( "<form method='post' action='/test_post'>"
79 "<input type='text' name='text' value='test text'><br>"
80 "<input type='submit' name='submit' value=' OK '></form>");
81 Send( "<pre style='background: #e0e0e0'>");
82 Send(GetMethod() + " " + GetUrl() + " " + GetHttpVersion() + "\n");
86 void HttpDebugSocket::OnHeader(const std::string& key,const std::string& value)
88 if (!strcasecmp(key.c_str(),"content-length"))
89 m_content_length = atoi(value.c_str());
91 Send(key + ": " + value + "\n");
95 void HttpDebugSocket::OnHeaderComplete()
97 if (m_content_length)
99 Send("</pre><h3>Request Body</h3><pre style='background: #e0e0e0'>");
101 else
103 Send("</pre><hr></body></html>");
104 SetCloseAndDelete();
109 void HttpDebugSocket::OnData(const char *p,size_t l)
111 SendBuf(p,l);
112 m_read_ptr += (int)l;
113 if (m_read_ptr >= m_content_length && m_content_length)
115 Send("</pre><hr></body></html>");
116 SetCloseAndDelete();
121 #ifdef SOCKETS_NAMESPACE
123 #endif