1 /** \file HttpGetSocket.cpp
3 ** \author grymse@alhem.net
6 Copyright (C) 2004-2007 Anders Hedstrom
8 This library is made available under the terms of the GNU GPL.
10 If you would like to use this library in a closed-source application,
11 a separate license agreement is available. For information about
12 the closed-source license agreement for the C++ sockets library,
13 please visit http://www.alhem.net/Sockets/license.html and/or
14 email license@alhem.net.
16 This program is free software; you can redistribute it and/or
17 modify it under the terms of the GNU General Public License
18 as published by the Free Software Foundation; either version 2
19 of the License, or (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #pragma warning(disable:4786)
39 #include "ISocketHandler.h"
40 #include "HttpGetSocket.h"
43 #ifdef SOCKETS_NAMESPACE
44 namespace SOCKETS_NAMESPACE
{
48 HttpGetSocket::HttpGetSocket(ISocketHandler
& h
) : HttpClientSocket(h
)
53 HttpGetSocket::HttpGetSocket(ISocketHandler
& h
,const std::string
& url_in
,const std::string
& to_file
) : HttpClientSocket(h
, url_in
)
59 if (!Open(GetUrlHost(),GetUrlPort()))
63 Handler().LogError(this, "HttpGetSocket", -1, "connect() failed miserably", LOG_LEVEL_FATAL
);
70 HttpGetSocket::HttpGetSocket(ISocketHandler
& h
,const std::string
& host
,port_t port
,const std::string
& url
,const std::string
& to_file
) : HttpClientSocket(h
)
77 if (!Open(host
, port
))
81 Handler().LogError(this, "HttpGetSocket", -1, "connect() failed miserably", LOG_LEVEL_FATAL
);
88 HttpGetSocket::~HttpGetSocket()
93 void HttpGetSocket::OnConnect()
96 AddResponseHeader( "Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1");
97 AddResponseHeader( "Accept-Language", "en-us,en;q=0.5");
98 AddResponseHeader( "Accept-Encoding", "gzip,deflate");
99 AddResponseHeader( "Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
100 AddResponseHeader( "User-agent", MyUseragent() );
102 if (GetUrlPort() != 80 && GetUrlPort() != 443)
103 AddResponseHeader( "Host", GetUrlHost() + ":" + Utility::l2string(GetUrlPort()) );
105 AddResponseHeader( "Host", GetUrlHost() );
110 #ifdef SOCKETS_NAMESPACE