summaryrefslogtreecommitdiff
path: root/protocols/Steam/src/http_request.h
blob: 4c7b83509ddc1518b0df6f3a246bc0226ba5fa4a (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
53
54
55
56
57
58
#ifndef _HTTP_REQUEST_H_
#define _HTTP_REQUEST_H_

#define STEAM_USER_AGENT "Valve/Steam HTTP Client 1.0"

class HttpResponse
{
	NETLIBHTTPREQUEST *m_response;

public:
	HttpResponse(NETLIBHTTPREQUEST *response) :
		m_response(response)
	{
	}

	~HttpResponse()
	{
		Netlib_FreeHttpRequest(m_response);
	}

	bool operator!() const
	{
		return !m_response || !m_response->pData;
	}

	operator bool() const
	{
		return m_response && m_response->pData;
	}

	bool IsSuccess() const
	{
		return m_response &&
			m_response->resultCode >= HTTP_CODE_OK &&
			m_response->resultCode <= HTTP_CODE_MULTI_STATUS;
	}

	char* data() const
	{
		return (m_response) ? m_response->pData : nullptr;
	}

	unsigned length() const
	{
		return (m_response) ? m_response->dataLength : 0;
	}

	LIST<NETLIBHTTPHEADER> Headers() const;

	int GetStatusCode() const
	{
		if (m_response)
			return m_response->resultCode;
		return 500;
	}
};

#endif //_HTTP_REQUEST_H_