summaryrefslogtreecommitdiff
path: root/protocols/Steam/src/http_request.h
blob: ac988a804a817ac50eb4d9bcc240e58a2369cab4 (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
#ifndef _HTTP_REQUEST_H_
#define _HTTP_REQUEST_H_

#define STEAM_USER_AGENT "Valve/Steam HTTP Client 1.0"

class HttpResponse
{
	MHttpResponse *m_response;

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

	~HttpResponse()
	{
		delete m_response;
	}

	bool operator!() const
	{
		return !m_response || m_response->body.IsEmpty();
	}

	operator bool() const
	{
		return m_response && !m_response->body.IsEmpty();
	}

	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->body.GetBuffer() : nullptr;
	}

	unsigned length() const
	{
		return (m_response) ? m_response->body.GetLength() : 0;
	}

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

#endif //_HTTP_REQUEST_H_