AWS SDK for C++

AWS SDK for C++ Version 1.11.440

Loading...
Searching...
No Matches
URI.h
1
6#pragma once
7
8#include <aws/core/Core_EXPORTS.h>
9
10#include <aws/core/http/Scheme.h>
11#include <aws/core/utils/memory/stl/AWSMap.h>
12#include <aws/core/utils/StringUtils.h>
13
14#include <stdint.h>
15
16namespace Aws
17{
18 namespace Http
19 {
20 extern AWS_CORE_API const char* SEPARATOR;
21 static const uint16_t HTTP_DEFAULT_PORT = 80;
22 static const uint16_t HTTPS_DEFAULT_PORT = 443;
23
25 AWS_CORE_API void SetCompliantRfc3986Encoding(bool compliant);
26
27 extern AWS_CORE_API bool s_preservePathSeparators;
28 AWS_CORE_API void SetPreservePathSeparators(bool preservePathSeparators);
29
30 //per https://tools.ietf.org/html/rfc3986#section-3.4 there is nothing preventing servers from allowing
31 //multiple values for the same key. So use a multimap instead of a map.
33
37 class AWS_CORE_API URI
38 {
39 public:
43 URI();
51 URI(const char*);
52
53 URI& operator = (const Aws::String&);
54 URI& operator = (const char*);
55
56 bool operator == (const URI&) const;
57 bool operator == (const Aws::String&) const;
58 bool operator == (const char*) const;
59 bool operator != (const URI&) const;
60 bool operator != (const Aws::String&) const;
61 bool operator != (const char*) const;
62
66 inline Scheme GetScheme() const { return m_scheme; }
67
71 void SetScheme(Scheme value);
72
76 inline const Aws::String& GetAuthority() const { return m_authority; }
77
81 inline void SetAuthority(const Aws::String& value) { m_authority = value; }
82
86 inline uint16_t GetPort() const { return m_port; }
87
92 inline void SetPort(uint16_t value) { m_port = value; }
93
99
104
109
113 void SetPath(const Aws::String& value);
114
120 template<typename T>
121 inline void AddPathSegment(T pathSegment)
122 {
124 ss << pathSegment;
125 Aws::String segment = ss.str();
126 segment.erase(0, segment.find_first_not_of('/'));
127 segment.erase(segment.find_last_not_of('/') + 1);
128 m_pathSegments.push_back(segment);
129 m_pathHasTrailingSlash = false;
130 }
131
135 template<typename T>
136 inline void AddPathSegments(T pathSegments)
137 {
139 ss << pathSegments;
140 Aws::String segments = ss.str();
141 const auto splitOption = s_preservePathSeparators
142 ? Utils::StringUtils::SplitOptions::INCLUDE_EMPTY_SEGMENTS
143 : Utils::StringUtils::SplitOptions::NOT_SET;
144 // Preserve legacy behavior -- we need to remove a leading "/" if use `INCLUDE_EMPTY_SEGMENTS` is specified
145 // because string split will no longer ignore leading delimiters -- which is correct.
146 auto split = Aws::Utils::StringUtils::Split(segments, '/', splitOption);
147 if (s_preservePathSeparators && m_pathSegments.empty() && !split.empty() && split.front().empty() && !m_pathHasTrailingSlash) {
148 split.erase(split.begin());
149 }
150 for (const auto& segment: split)
151 {
152 m_pathSegments.push_back(segment);
153 }
154 m_pathHasTrailingSlash = (!segments.empty() && segments.back() == '/');
155 }
156
160 inline const Aws::String& GetQueryString() const { return m_queryString; }
161
165 void SetQueryString(const Aws::String& str);
166
168
173
179
183 void AddQueryStringParameter(const char* key, const Aws::String& value);
184
189
193 Aws::String GetURIString(bool includeQueryString = true) const;
194
198 inline bool IsRfc3986Encoded() const { return m_useRfcEncoding; }
199
203 inline void SetRfc3986Encoded(const bool value) { m_useRfcEncoding = value; }
204
210
214 static Aws::String URLEncodePathRFC3986(const Aws::String& path, bool rfcCompliantEncoding = false);
215
216 private:
217 void ParseURIParts(const Aws::String& uri);
218 void ExtractAndSetScheme(const Aws::String& uri);
219 void ExtractAndSetAuthority(const Aws::String& uri);
220 void ExtractAndSetPort(const Aws::String& uri);
221 void ExtractAndSetPath(const Aws::String& uri);
222 void ExtractAndSetQueryString(const Aws::String& uri);
223 bool CompareURIParts(const URI& other) const;
224
225 Scheme m_scheme = Scheme::HTTP;
226 Aws::String m_authority;
227 uint16_t m_port = HTTP_DEFAULT_PORT;
228 Aws::Vector<Aws::String> m_pathSegments;
229 bool m_pathHasTrailingSlash = false;
230 bool m_useRfcEncoding = false;
231 Aws::String m_queryString;
232 };
233
234 } // namespace Http
235} // namespace Aws
236
URI(const Aws::String &)
void CanonicalizeQueryString()
void SetRfc3986Encoded(const bool value)
Definition URI.h:203
void SetScheme(Scheme value)
static Aws::String URLEncodePathRFC3986(const Aws::String &path, bool rfcCompliantEncoding=false)
Aws::String GetFormParameters() const
void AddQueryStringParameter(const char *key, const Aws::String &value)
void AddQueryStringParameter(const Aws::Map< Aws::String, Aws::String > &queryStringPairs)
void SetPath(const Aws::String &value)
void AddPathSegments(T pathSegments)
Definition URI.h:136
static Aws::String URLEncodePath(const Aws::String &path)
Aws::String GetURIString(bool includeQueryString=true) const
const Aws::String & GetAuthority() const
Definition URI.h:76
const Aws::String & GetQueryString() const
Definition URI.h:160
Aws::String GetURLEncodedPath() const
QueryStringParameterCollection GetQueryStringParameters(bool decode=true) const
Aws::String GetURLEncodedPathRFC3986() const
void SetAuthority(const Aws::String &value)
Definition URI.h:81
Scheme GetScheme() const
Definition URI.h:66
void AddPathSegment(T pathSegment)
Definition URI.h:121
uint16_t GetPort() const
Definition URI.h:86
bool IsRfc3986Encoded() const
Definition URI.h:198
void SetQueryString(const Aws::String &str)
URI(const char *)
void SetPort(uint16_t value)
Definition URI.h:92
Aws::String GetPath() const
static Aws::Vector< Aws::String > Split(const Aws::String &toSplit, char splitOn)
Splits a string on a delimiter (empty items are excluded).
AWS_CORE_API void SetPreservePathSeparators(bool preservePathSeparators)
Aws::MultiMap< Aws::String, Aws::String > QueryStringParameterCollection
Definition URI.h:32
bool s_compliantRfc3986Encoding
AWS_CORE_API bool s_preservePathSeparators
static const uint16_t HTTPS_DEFAULT_PORT
Definition URI.h:22
static const uint16_t HTTP_DEFAULT_PORT
Definition URI.h:21
AWS_CORE_API const char * SEPARATOR
AWS_CORE_API void SetCompliantRfc3986Encoding(bool compliant)
std::basic_stringstream< char, std::char_traits< char >, Aws::Allocator< char > > StringStream
std::map< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > > Map
Definition AWSMap.h:20
std::multimap< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > > MultiMap
Definition AWSMap.h:22
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition AWSString.h:97
std::vector< T, Aws::Allocator< T > > Vector
Definition AWSVector.h:17