summaryrefslogtreecommitdiff
path: root/src/modules/fetcher/winhttp/WinHttpFetcher.cpp
blob: 19227f18099eae4605053452e2c791d1f37666f4 (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 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 )