blob: 5c8839dace9d4f6d0ea5a257b516f9d2f06c0146 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include "WinHttpFetcher.hpp"
#include "WinHttpRewindInputStream.hpp"
#include "win32/errormsg.hpp"
#include <sstream>
#include <stdexcept>
WinHttpFetcher::WinHttpFetcher( )
: m_session( 0 )
{
m_session = WinHttpOpen( L"WinHTTP crawler/0.0.1",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0 );
if( !m_session ) {
std::ostringstream ss;
ss << "Error creating WinHttp session: " << getLastError( );
throw new std::runtime_error( ss.str( ) );
}
}
WinHttpFetcher::~WinHttpFetcher( )
{
WinHttpCloseHandle( m_session );
}
RewindInputStream *WinHttpFetcher::fetch( const URL url )
{
WinHttpRewindInputStream *s = new WinHttpRewindInputStream( url, this );
return s;
}
REGISTER_MODULE( "winhttp_fetcher", 0, 0, Fetcher, WinHttpFetcher )
|