aws-crt-cpp
HttpRequestResponse.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License").
6  * You may not use this file except in compliance with the License.
7  * A copy of the License is located at
8  *
9  * http://aws.amazon.com/apache2.0
10  *
11  * or in the "license" file accompanying this file. This file is distributed
12  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16 
17 #include <aws/crt/Exports.h>
18 #include <aws/crt/Types.h>
19 #include <aws/crt/io/Stream.h>
20 
21 struct aws_http_header;
22 struct aws_http_message;
23 
24 namespace Aws
25 {
26  namespace Crt
27  {
28  namespace Mqtt
29  {
30  class MqttConnection;
31  }
32 
33  namespace Http
34  {
35  using HttpHeader = aws_http_header;
36 
41  {
42  public:
43  virtual ~HttpMessage();
44 
45  HttpMessage(const HttpMessage &) = delete;
46  HttpMessage(HttpMessage &&) = delete;
47  HttpMessage &operator=(const HttpMessage &) = delete;
49 
53  std::shared_ptr<Aws::Crt::Io::InputStream> GetBody() const noexcept;
54 
58  bool SetBody(const std::shared_ptr<Aws::Crt::Io::IStream> &body) noexcept;
59 
60  bool SetBody(const std::shared_ptr<Aws::Crt::Io::InputStream> &body) noexcept;
61 
62  size_t GetHeaderCount() const noexcept;
63  Optional<HttpHeader> GetHeader(size_t index) const noexcept;
64  bool AddHeader(const HttpHeader &header) noexcept;
65  bool EraseHeader(size_t index) noexcept;
66 
67  operator bool() const noexcept { return m_message != nullptr; }
68 
69  struct aws_http_message *GetUnderlyingMessage() const noexcept { return m_message; }
70 
71  protected:
72  HttpMessage(Allocator *allocator, struct aws_http_message *message, bool ownsMessage = true) noexcept;
73 
74  Allocator *m_allocator;
75  struct aws_http_message *m_message;
76  std::shared_ptr<Aws::Crt::Io::InputStream> m_bodyStream;
77  bool m_ownsMessage;
78  };
79 
84  {
85  friend class Mqtt::MqttConnection;
86 
87  public:
88  HttpRequest(Allocator *allocator = g_allocator);
89 
93  Optional<ByteCursor> GetMethod() const noexcept;
94 
98  bool SetMethod(ByteCursor method) noexcept;
99 
103  Optional<ByteCursor> GetPath() const noexcept;
104 
108  bool SetPath(ByteCursor path) noexcept;
109 
110  protected:
111  HttpRequest(Allocator *allocator, struct aws_http_message *message);
112  };
113 
118  {
119  public:
120  HttpResponse(Allocator *allocator = g_allocator);
121 
125  Optional<int> GetResponseCode() const noexcept;
126 
130  bool SetResponseCode(int response) noexcept;
131  };
132  } // namespace Http
133  } // namespace Crt
134 } // namespace Aws
Aws::Crt::Allocator
aws_allocator Allocator
Definition: StlAllocator.h:25
Aws::Crt::Http::HttpMessage::HttpMessage
HttpMessage(HttpMessage &&)=delete
Types.h
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:34
Aws::Crt::Http::HttpMessage::operator=
HttpMessage & operator=(const HttpMessage &)=delete
Aws::Crt::Http::HttpRequest
Definition: HttpRequestResponse.h:84
Aws::Crt::Http::HttpMessage::operator=
HttpMessage & operator=(HttpMessage &&)=delete
Aws::Crt::Io::IStream
std::basic_istream< char, std::char_traits< char > > IStream
Definition: Types.h:48
Aws::Crt::ByteCursor
aws_byte_cursor ByteCursor
Definition: Types.h:44
Aws::Crt::g_allocator
Allocator * g_allocator
Definition: Api.cpp:28
Aws::Crt::Http::HttpMessage
Definition: HttpRequestResponse.h:41
Aws::Crt::Http::HttpResponse
Definition: HttpRequestResponse.h:118
Aws
Definition: Api.h:25
Aws::Crt::Http::HttpMessage::HttpMessage
HttpMessage(const HttpMessage &)=delete
Exports.h
Aws::Crt::Optional
Definition: Optional.h:32
Aws::Crt::Mqtt::MqttConnection
Definition: MqttClient.h:118
Aws::Crt::Http::HttpHeader
aws_http_header HttpHeader
Definition: HttpConnection.h:42
Aws::Crt::Http::HttpMessage::GetUnderlyingMessage
struct aws_http_message * GetUnderlyingMessage() const noexcept
Definition: HttpRequestResponse.h:69
Stream.h
Aws::index
int index
Definition: cJSON.h:180