AWS SDK for C++

AWS SDK for C++ Version 1.11.606

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
77 inline const Aws::String& GetAuthority() const { return m_authority; }
78
83 inline void SetAuthority(const Aws::String& value) { m_authority = value; }
84
88 inline uint16_t GetPort() const { return m_port; }
89
94 inline void SetPort(uint16_t value) { m_port = value; }
95
101
106
111
115 void SetPath(const Aws::String& value);
116
122 template<typename T>
123 inline void AddPathSegment(T pathSegment)
124 {
126 ss << pathSegment;
127 Aws::String segment = ss.str();
128 segment.erase(0, segment.find_first_not_of('/'));
129 segment.erase(segment.find_last_not_of('/') + 1);
130 m_pathSegments.push_back(segment);
131 m_pathHasTrailingSlash = false;
132 }
133
137 template<typename T>
138 inline void AddPathSegments(T pathSegments)
139 {
141 ss << pathSegments;
142 Aws::String segments = ss.str();
143 const auto splitOption = s_preservePathSeparators
144 ? Utils::StringUtils::SplitOptions::INCLUDE_EMPTY_SEGMENTS
145 : Utils::StringUtils::SplitOptions::NOT_SET;
146 // Preserve legacy behavior -- we need to remove a leading "/" if use `INCLUDE_EMPTY_SEGMENTS` is specified
147 // because string split will no longer ignore leading delimiters -- which is correct.
148 auto split = Aws::Utils::StringUtils::Split(segments, '/', splitOption);
149 if (s_preservePathSeparators && m_pathSegments.empty() && !split.empty() && split.front().empty() && !m_pathHasTrailingSlash) {
150 split.erase(split.begin());
151 }
152 for (const auto& segment: split)
153 {
154 m_pathSegments.push_back(segment);
155 }
156 m_pathHasTrailingSlash = (!segments.empty() && segments.back() == '/');
157 }
158
162 inline const Aws::String& GetQueryString() const { return m_queryString; }
163
167 void SetQueryString(const Aws::String& str);
168
170
175
181
185 void AddQueryStringParameter(const char* key, const Aws::String& value);
186
191
195 Aws::String GetURIString(bool includeQueryString = true) const;
196
200 inline bool IsRfc3986Encoded() const { return m_useRfcEncoding; }
201
205 inline void SetRfc3986Encoded(const bool value) { m_useRfcEncoding = value; }
206
212
216 static Aws::String URLEncodePathRFC3986(const Aws::String& path, bool rfcCompliantEncoding = false);
217
228
229 private:
230 void ParseURIParts(const Aws::String& uri);
231 void ExtractAndSetScheme(const Aws::String& uri);
232 void ExtractAndSetAuthority(const Aws::String& uri);
233 void ExtractAndSetPort(const Aws::String& uri);
234 void ExtractAndSetPath(const Aws::String& uri);
235 void ExtractAndSetQueryString(const Aws::String& uri);
236 bool CompareURIParts(const URI& other) const;
237
238 Scheme m_scheme = Scheme::HTTP;
239 Aws::String m_authority;
240 uint16_t m_port = HTTP_DEFAULT_PORT;
241 Aws::Vector<Aws::String> m_pathSegments;
242 bool m_pathHasTrailingSlash = false;
243 bool m_useRfcEncoding = false;
244 Aws::String m_queryString;
245 };
246
247 } // namespace Http
248} // namespace Aws
249
URI(const Aws::String &)
void CanonicalizeQueryString()
void SetRfc3986Encoded(const bool value)
Definition URI.h:205
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:138
static Aws::String URLEncodePath(const Aws::String &path)
Aws::String GetURIString(bool includeQueryString=true) const
const Aws::String & GetAuthority() const
Definition URI.h:77
Aws::String GetHost() const
const Aws::String & GetQueryString() const
Definition URI.h:162
Aws::String GetURLEncodedPath() const
QueryStringParameterCollection GetQueryStringParameters(bool decode=true) const
Aws::String GetURLEncodedPathRFC3986() const
void SetAuthority(const Aws::String &value)
Definition URI.h:83
Scheme GetScheme() const
Definition URI.h:66
void AddPathSegment(T pathSegment)
Definition URI.h:123
uint16_t GetPort() const
Definition URI.h:88
bool IsRfc3986Encoded() const
Definition URI.h:200
void SetQueryString(const Aws::String &str)
URI(const char *)
void SetPort(uint16_t value)
Definition URI.h:94
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