AWS SDK for C++  1.9.123
AWS SDK for C++
URI.h
Go to the documentation of this file.
1 
6 #pragma once
7 
9 
10 #include <aws/core/http/Scheme.h>
13 
14 #include <stdint.h>
15 
16 namespace 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 
24  //per https://tools.ietf.org/html/rfc3986#section-3.4 there is nothing preventing servers from allowing
25  //multiple values for the same key. So use a multimap instead of a map.
27 
32  {
33  public:
37  URI();
41  URI(const Aws::String&);
45  URI(const char*);
46 
47  URI& operator = (const Aws::String&);
48  URI& operator = (const char*);
49 
50  bool operator == (const URI&) const;
51  bool operator == (const Aws::String&) const;
52  bool operator == (const char*) const;
53  bool operator != (const URI&) const;
54  bool operator != (const Aws::String&) const;
55  bool operator != (const char*) const;
56 
60  inline Scheme GetScheme() const { return m_scheme; }
61 
65  void SetScheme(Scheme value);
66 
70  inline const Aws::String& GetAuthority() const { return m_authority; }
71 
75  inline void SetAuthority(const Aws::String& value) { m_authority = value; }
76 
80  inline uint16_t GetPort() const { return m_port; }
81 
86  inline void SetPort(uint16_t value) { m_port = value; }
87 
93 
98 
103 
107  void SetPath(const Aws::String& value);
108 
114  template<typename T>
115  inline void AddPathSegment(T pathSegment)
116  {
118  ss << pathSegment;
119  Aws::String segment = ss.str();
120  segment.erase(0, segment.find_first_not_of('/'));
121  segment.erase(segment.find_last_not_of('/') + 1);
122  m_pathSegments.push_back(segment);
123  m_pathHasTrailingSlash = false;
124  }
125 
129  template<typename T>
130  inline void AddPathSegments(T pathSegments)
131  {
133  ss << pathSegments;
134  Aws::String segments = ss.str();
135  for (const auto& segment : Aws::Utils::StringUtils::Split(segments, '/'))
136  {
137  m_pathSegments.push_back(segment);
138  }
139  m_pathHasTrailingSlash = (!segments.empty() && segments.back() == '/');
140  }
141 
145  inline const Aws::String& GetQueryString() const { return m_queryString; }
146 
150  void SetQueryString(const Aws::String& str);
151 
153 
158 
164 
168  void AddQueryStringParameter(const char* key, const Aws::String& value);
169 
174 
178  Aws::String GetURIString(bool includeQueryString = true) const;
179 
184  static Aws::String URLEncodePath(const Aws::String& path);
185 
190 
191  private:
192  void ParseURIParts(const Aws::String& uri);
193  void ExtractAndSetScheme(const Aws::String& uri);
194  void ExtractAndSetAuthority(const Aws::String& uri);
195  void ExtractAndSetPort(const Aws::String& uri);
196  void ExtractAndSetPath(const Aws::String& uri);
197  void ExtractAndSetQueryString(const Aws::String& uri);
198  bool CompareURIParts(const URI& other) const;
199 
200  Scheme m_scheme;
201  Aws::String m_authority;
202  uint16_t m_port;
203  Aws::Vector<Aws::String> m_pathSegments;
204  bool m_pathHasTrailingSlash;
205  Aws::String m_queryString;
206  };
207 
208  } // namespace Http
209 } // namespace Aws
210 
Aws::Http::URI::GetQueryString
const Aws::String & GetQueryString() const
Definition: URI.h:145
Aws::Http::URI
Definition: URI.h:32
Aws::Http::URI::SetScheme
void SetScheme(Scheme value)
AWS_CORE_API
#define AWS_CORE_API
Definition: Core_EXPORTS.h:25
Aws::Http::Scheme
Scheme
Definition: Scheme.h:20
Aws::Http::URI::GetURIString
Aws::String GetURIString(bool includeQueryString=true) const
Aws::Http::URI::CanonicalizeQueryString
void CanonicalizeQueryString()
Aws::Http::URI::SetAuthority
void SetAuthority(const Aws::String &value)
Definition: URI.h:75
Aws::Vector
std::vector< T, Aws::Allocator< T > > Vector
Definition: AWSVector.h:17
Aws::Http::URI::URLEncodePathRFC3986
static Aws::String URLEncodePathRFC3986(const Aws::String &path)
Aws::Http::HTTP_DEFAULT_PORT
static const uint16_t HTTP_DEFAULT_PORT
Definition: URI.h:21
Aws::Http::URI::GetQueryStringParameters
QueryStringParameterCollection GetQueryStringParameters(bool decode=true) const
Aws::Http::URI::GetFormParameters
Aws::String GetFormParameters() const
Aws::Http::QueryStringParameterCollection
Aws::MultiMap< Aws::String, Aws::String > QueryStringParameterCollection
Definition: URI.h:26
Aws::Http::URI::SetQueryString
void SetQueryString(const Aws::String &str)
Aws::Http::URI::AddPathSegments
void AddPathSegments(T pathSegments)
Definition: URI.h:130
Aws::Utils::StringUtils::Split
static Aws::Vector< Aws::String > Split(const Aws::String &toSplit, char splitOn)
Splits a string on a delimiter (empty items are excluded).
Aws::Http::URI::AddQueryStringParameter
void AddQueryStringParameter(const Aws::Map< Aws::String, Aws::String > &queryStringPairs)
Aws::Http::URI::SetPath
void SetPath(const Aws::String &value)
Aws::Http::URI::SetPort
void SetPort(uint16_t value)
Definition: URI.h:86
Aws::Http::URI::GetURLEncodedPath
Aws::String GetURLEncodedPath() const
Aws::Http::URI::GetAuthority
const Aws::String & GetAuthority() const
Definition: URI.h:70
StringUtils.h
Aws::Http::URI::GetPort
uint16_t GetPort() const
Definition: URI.h:80
Core_EXPORTS.h
Aws::Http::URI::AddPathSegment
void AddPathSegment(T pathSegment)
Definition: URI.h:115
Scheme.h
Aws::Http::SEPARATOR
AWS_CORE_API const char * SEPARATOR
Aws
Definition: AccessManagementClient.h:15
Aws::MultiMap
std::multimap< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > > MultiMap
Definition: AWSMap.h:21
Aws::Http::URI::GetPath
Aws::String GetPath() const
Aws::Http::URI::URI
URI()
Aws::Http::URI::URI
URI(const char *)
Aws::String
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
Aws::Http::URI::URI
URI(const Aws::String &)
Aws::Http::URI::AddQueryStringParameter
void AddQueryStringParameter(const char *key, const Aws::String &value)
Aws::Http::URI::GetScheme
Scheme GetScheme() const
Definition: URI.h:60
AWSMap.h
Aws::Http::HTTPS_DEFAULT_PORT
static const uint16_t HTTPS_DEFAULT_PORT
Definition: URI.h:22
Aws::StringStream
std::basic_stringstream< char, std::char_traits< char >, Aws::Allocator< char > > StringStream
Definition: AWSStringStream.h:35
Aws::Http::URI::GetURLEncodedPathRFC3986
Aws::String GetURLEncodedPathRFC3986() const
Aws::Map
std::map< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > > Map
Definition: AWSMap.h:19
Aws::Http::URI::URLEncodePath
static Aws::String URLEncodePath(const Aws::String &path)