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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <aws/core/http/HttpTypes.h>
#include <utility>
#include <aws/core/http/HttpResponse.h>
namespace Aws
{
/**
* Container for web response to an AWS Request.
*/
template <typename PAYLOAD_TYPE>
class AmazonWebServiceResult
{
public:
AmazonWebServiceResult() : m_responseCode(Http::HttpResponseCode::REQUEST_NOT_MADE) {}
/**
* Sets payload, header collection and a response code.
*/
AmazonWebServiceResult(const PAYLOAD_TYPE& payload, const Http::HeaderValueCollection& headers, Http::HttpResponseCode responseCode = Http::HttpResponseCode::OK) :
m_payload(payload),
m_responseHeaders(headers),
m_responseCode(responseCode)
{}
/**
* Sets payload, header collection and a response code, but transfers ownership of payload and headers (for move only operations).
*/
AmazonWebServiceResult(PAYLOAD_TYPE&& payload, Http::HeaderValueCollection&& headers, Http::HttpResponseCode responseCode = Http::HttpResponseCode::OK) :
m_payload(std::forward<PAYLOAD_TYPE>(payload)),
m_responseHeaders(std::forward<Http::HeaderValueCollection>(headers)),
m_responseCode(responseCode)
{}
AmazonWebServiceResult(const AmazonWebServiceResult& result) :
m_payload(result.m_payload),
m_responseHeaders(result.m_responseHeaders),
m_responseCode(result.m_responseCode)
{}
AmazonWebServiceResult(AmazonWebServiceResult&& result) :
m_payload(std::move(result.m_payload)),
m_responseHeaders(std::move(result.m_responseHeaders)),
m_responseCode(result.m_responseCode)
{}
/**
* Get the payload from the response
*/
inline const PAYLOAD_TYPE& GetPayload() const { return m_payload; }
/**
* Get the payload from the response and take ownership of it.
*/
inline PAYLOAD_TYPE&& TakeOwnershipOfPayload() { return std::move(m_payload); }
/**
* Get the headers from the response
*/
inline const Http::HeaderValueCollection& GetHeaderValueCollection() const { return m_responseHeaders; }
/**
* Get the http response code from the response
*/
inline Http::HttpResponseCode GetResponseCode() const { return m_responseCode; }
private:
PAYLOAD_TYPE m_payload;
Http::HeaderValueCollection m_responseHeaders;
Http::HttpResponseCode m_responseCode;
};
}
|