summaryrefslogtreecommitdiff
path: root/protocols/Steam/src/steam_request.cpp
blob: 918e01ca165242431ffae08195311a98ed174742 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "stdafx.h"

bool CSteamProto::SendRequest(HttpRequest *request)
{
	auto *pResp = Netlib_HttpTransaction(m_hNetlibUser, request->Get());
	HttpResponse response(pResp);
	delete request;
	return response.IsSuccess();
}

bool CSteamProto::SendRequest(HttpRequest *request, HttpCallback callback, void *param)
{
	auto *pResp = Netlib_HttpTransaction(m_hNetlibUser, request->Get());
	HttpResponse response(pResp);
	if (callback)
		(this->*callback)(response, param);
	delete request;
	return response.IsSuccess();
}

bool CSteamProto::SendRequest(HttpRequest *request, JsonCallback callback, void *param)
{
	auto *pResp = Netlib_HttpTransaction(m_hNetlibUser, request->Get());
	HttpResponse response(pResp);
	if (callback) {
		JSONNode root = JSONNode::parse(response.data());
		(this->*callback)(root, param);
	}
	delete request;
	return response.IsSuccess();
}

/////////////////////////////////////////////////////////////////////////////////////////
// HttpRequest

HttpRequest::HttpRequest(int iRequestType, const char *szUrl)
{
	flags = NLHRF_SSL | NLHRF_HTTP11 | NLHRF_REDIRECT | NLHRF_DUMPASTEXT;
	requestType = iRequestType;
	timeout = 30000;
	if (szUrl)
		m_szUrl = szUrl;
}

MHttpRequest* HttpRequest::Get()
{
	if (m_szUrl[0]== '/') {
		m_szUrl.Insert(0, STEAM_API_URL);
		AddHeader("User-Agent", STEAM_USER_AGENT);
	}
	return this;
}