00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifdef _WIN32
00031 #ifdef _MSC_VER
00032 #pragma warning(disable:4786)
00033 #endif
00034 #else
00035 #include <errno.h>
00036 #endif
00037 #include "Utility.h"
00038 #include "ISocketHandler.h"
00039 #include "HttpGetSocket.h"
00040
00041
00042 #ifdef SOCKETS_NAMESPACE
00043 namespace SOCKETS_NAMESPACE {
00044 #endif
00045
00046
00047 HttpGetSocket::HttpGetSocket(ISocketHandler& h) : HttpClientSocket(h)
00048 {
00049 }
00050
00051
00052 HttpGetSocket::HttpGetSocket(ISocketHandler& h,const std::string& url_in,const std::string& to_file) : HttpClientSocket(h, url_in)
00053 {
00054 if (to_file.size())
00055 {
00056 SetFilename(to_file);
00057 }
00058 if (!Open(GetUrlHost(),GetUrlPort()))
00059 {
00060 if (!Connecting())
00061 {
00062 Handler().LogError(this, "HttpGetSocket", -1, "connect() failed miserably", LOG_LEVEL_FATAL);
00063 SetCloseAndDelete();
00064 }
00065 }
00066 }
00067
00068
00069 HttpGetSocket::HttpGetSocket(ISocketHandler& h,const std::string& host,port_t port,const std::string& url,const std::string& to_file) : HttpClientSocket(h, host, port, url)
00070 {
00071 SetUrl(url);
00072 if (to_file.size())
00073 {
00074 SetFilename(to_file);
00075 }
00076 if (!Open(host, port))
00077 {
00078 if (!Connecting())
00079 {
00080 Handler().LogError(this, "HttpGetSocket", -1, "connect() failed miserably", LOG_LEVEL_FATAL);
00081 SetCloseAndDelete();
00082 }
00083 }
00084 }
00085
00086
00087 HttpGetSocket::~HttpGetSocket()
00088 {
00089 }
00090
00091
00092 void HttpGetSocket::OnConnect()
00093 {
00094 SetMethod( "GET" );
00095 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");
00096 AddResponseHeader( "Accept-Language", "en-us,en;q=0.5");
00097 AddResponseHeader( "Accept-Encoding", "gzip,deflate");
00098 AddResponseHeader( "Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
00099 AddResponseHeader( "User-agent", MyUseragent() );
00100
00101 if (GetUrlPort() != 80 && GetUrlPort() != 443)
00102 AddResponseHeader( "Host", GetUrlHost() + ":" + Utility::l2string(GetUrlPort()) );
00103 else
00104 AddResponseHeader( "Host", GetUrlHost() );
00105 SendRequest();
00106 }
00107
00108
00109 #ifdef SOCKETS_NAMESPACE
00110 }
00111 #endif
00112
00113