AWS IoT Device SDK C++ v2  1.34.0
AWS IoT Device SDK C++ v2
HttpRequestResponse.h
Go to the documentation of this file.
1 #pragma once
2 
7 #include <aws/crt/Exports.h>
8 #include <aws/crt/Types.h>
9 #include <aws/crt/io/Stream.h>
10 
11 struct aws_http_header;
12 struct aws_http_message;
13 
14 namespace Aws
15 {
16  namespace Crt
17  {
18  namespace Mqtt
19  {
20  class MqttConnection;
21  class MqttConnectionCore;
22  } // namespace Mqtt
23  namespace Mqtt5
24  {
25  class Mqtt5ClientCore;
26  }
27  namespace Http
28  {
29  using HttpHeader = aws_http_header;
30 
35  {
36  public:
37  virtual ~HttpMessage();
38 
39  HttpMessage(const HttpMessage &) = delete;
40  HttpMessage(HttpMessage &&) = delete;
41  HttpMessage &operator=(const HttpMessage &) = delete;
43 
47  std::shared_ptr<Aws::Crt::Io::InputStream> GetBody() const noexcept;
48 
54  bool SetBody(const std::shared_ptr<Aws::Crt::Io::IStream> &body) noexcept;
55 
61  bool SetBody(const std::shared_ptr<Aws::Crt::Io::InputStream> &body) noexcept;
62 
67  size_t GetHeaderCount() const noexcept;
68 
74  Optional<HttpHeader> GetHeader(size_t index) const noexcept;
75 
81  bool AddHeader(const HttpHeader &header) noexcept;
82 
88  bool EraseHeader(size_t index) noexcept;
89 
93  operator bool() const noexcept { return m_message != nullptr; }
94 
96  struct aws_http_message *GetUnderlyingMessage() const noexcept { return m_message; }
97 
98  protected:
99  HttpMessage(Allocator *allocator, struct aws_http_message *message) noexcept;
100 
102  struct aws_http_message *m_message;
103  std::shared_ptr<Aws::Crt::Io::InputStream> m_bodyStream;
104  };
105 
110  {
111  friend class Mqtt::MqttConnectionCore;
112  friend class Mqtt5::Mqtt5ClientCore;
113 
114  public:
115  HttpRequest(Allocator *allocator = ApiAllocator());
116 
120  Optional<ByteCursor> GetMethod() const noexcept;
121 
125  bool SetMethod(ByteCursor method) noexcept;
126 
130  Optional<ByteCursor> GetPath() const noexcept;
131 
135  bool SetPath(ByteCursor path) noexcept;
136 
137  protected:
138  HttpRequest(Allocator *allocator, struct aws_http_message *message);
139  };
140 
145  {
146  public:
147  HttpResponse(Allocator *allocator = ApiAllocator());
148 
152  Optional<int> GetResponseCode() const noexcept;
153 
157  bool SetResponseCode(int response) noexcept;
158  };
159  } // namespace Http
160  } // namespace Crt
161 } // namespace Aws
Aws::Crt::Http::HttpMessage::m_bodyStream
std::shared_ptr< Aws::Crt::Io::InputStream > m_bodyStream
Definition: HttpRequestResponse.h:103
Aws::Crt::Http::HttpMessage::operator=
HttpMessage & operator=(HttpMessage &&)=delete
Aws::Crt::Http::HttpResponse
Definition: HttpRequestResponse.h:145
Aws::Crt::ApiAllocator
AWS_CRT_CPP_API Allocator * ApiAllocator() noexcept
Definition: Allocator.cpp:24
Aws::Crt::Http::HttpHeader
aws_http_header HttpHeader
Definition: HttpConnection.h:34
Aws::Crt::Http::HttpRequest
Definition: HttpRequestResponse.h:110
Aws::Crt::Http::HttpMessage
Definition: HttpRequestResponse.h:35
Aws::Crt::Io::IStream
std::basic_istream< char, std::char_traits< char > > IStream
Definition: Types.h:35
Aws::Crt::Http::HttpMessage::HttpMessage
HttpMessage(HttpMessage &&)=delete
Aws::Crt::Mqtt::MqttConnection
Definition: MqttConnection.h:158
Aws::Crt::Optional
Definition: Optional.h:18
Types.h
Aws::Crt::Http::HttpMessage::operator=
HttpMessage & operator=(const HttpMessage &)=delete
std
Definition: StringView.h:852
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Aws
Definition: Allocator.h:11
Aws::Crt::Http::HttpMessage::m_allocator
Allocator * m_allocator
Definition: HttpRequestResponse.h:101
Aws::Crt::ByteCursor
aws_byte_cursor ByteCursor
Definition: Types.h:31
Aws::Crt::Http::HttpMessage::HttpMessage
HttpMessage(const HttpMessage &)=delete
Aws::Crt::Allocator
aws_allocator Allocator
Definition: Allocator.h:14
Exports.h
Aws::Crt::Http::HttpMessage::m_message
struct aws_http_message * m_message
Definition: HttpRequestResponse.h:102
Stream.h