1 /** \file HttpDebugSocket.cpp
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.
30 #pragma warning(disable:4786)
32 #include "HttpDebugSocket.h"
34 #include "ISocketHandler.h"
37 #ifdef SOCKETS_NAMESPACE
38 namespace SOCKETS_NAMESPACE
{
42 HttpDebugSocket::HttpDebugSocket(ISocketHandler
& h
) : HTTPSocket(h
)
49 HttpDebugSocket::~HttpDebugSocket()
54 void HttpDebugSocket::Init()
56 if (GetParent() -> GetPort() == 443)
61 Handler().LogError(this, "url_this", -1, "SSL not available", LOG_LEVEL_WARNING
);
67 void HttpDebugSocket::OnFirst()
71 "Content-type: text/html\n"
73 "Server: HttpDebugSocket/1.0\n"
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()
99 Send("</pre><h3>Request Body</h3><pre style='background: #e0e0e0'>");
103 Send("</pre><hr></body></html>");
109 void HttpDebugSocket::OnData(const char *p
,size_t l
)
112 m_read_ptr
+= (int)l
;
113 if (m_read_ptr
>= m_content_length
&& m_content_length
)
115 Send("</pre><hr></body></html>");
121 #ifdef SOCKETS_NAMESPACE