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