5#ifndef WPINET_HTTPUTIL_H_
6#define WPINET_HTTPUTIL_H_
8#include <initializer_list>
40 bool spacePlus =
true);
59 std::string* saveBuf);
128 explicit operator bool()
const {
return !
empty(); }
146 bool equals(std::initializer_list<std::string_view> match)
const {
147 return equals(0, {match.begin(), match.end()});
149 bool equals(std::span<const std::string_view> match)
const {
163 std::initializer_list<std::string_view> match)
const {
164 return equals(start, {match.begin(), match.end()});
166 bool equals(
size_t start, std::span<const std::string_view> match)
const {
167 if (m_pathEnds.
size() != (start + match.size())) {
173 return equals(start, {match});
183 bool startswith(std::initializer_list<std::string_view> match)
const {
184 return startswith(0, {match.begin(), match.end()});
186 bool startswith(std::span<const std::string_view> match)
const {
202 std::initializer_list<std::string_view> match)
const {
203 return startswith(start, {match.begin(), match.end()});
206 bool startswith(
size_t start, std::span<const std::string_view> match)
const;
235 : m_path(&path), m_start(start) {}
237 explicit operator bool()
const {
return !
empty(); }
238 bool empty()
const {
return m_path && m_path->
size() == m_start; }
239 size_t size()
const {
return m_path ? m_path->
size() - m_start : 0; }
241 bool equals(std::initializer_list<std::string_view> match)
const {
242 return equals(0, {match.begin(), match.end()});
244 bool equals(std::span<const std::string_view> match)
const {
250 std::initializer_list<std::string_view> match)
const {
251 return equals(start, {match.begin(), match.end()});
253 bool equals(
size_t start, std::span<const std::string_view> match)
const {
254 return m_path ? m_path->
equals(m_start + start, match) :
false;
257 return equals(start, {match});
260 bool startswith(std::initializer_list<std::string_view> match)
const {
261 return startswith(0, {match.begin(), match.end()});
263 bool startswith(std::span<const std::string_view> match)
const {
271 std::initializer_list<std::string_view> match)
const {
272 return startswith(start, {match.begin(), match.end()});
274 bool startswith(
size_t start, std::span<const std::string_view> match)
const {
275 return m_path ? m_path->
startswith(m_start + start, match) :
false;
304 std::vector<std::pair<std::string, std::string>>
params;
318 template <
typename T>
326 template <
typename T>
329 SetPath(path_, params);
340 template <
typename T>
343 template <
typename T>
347 template <
typename T>
351 template <
typename T>
364 std::unique_ptr<wpi::NetworkStream>
stream;
378 bool saveSkipped =
false) {
388 void Reset(
bool saveSkipped =
false);
397 bool IsDone()
const {
return m_state == kDone; }
408 enum State { kBoundary, kPadding, kDone };
410 size_t m_posWith, m_posWithout;
411 enum Dashes { kUnknown, kWith, kWithout };
This file defines the SmallString class.
This file defines the StringMap class.
Definition: HttpUtil.h:357
SmallString< 64 > contentType
Definition: HttpUtil.h:369
SmallString< 64 > contentLength
Definition: HttpUtil.h:370
bool Handshake(const HttpRequest &request, std::string *warnMsg)
wpi::raw_socket_ostream os
Definition: HttpUtil.h:366
HttpConnection(std::unique_ptr< wpi::NetworkStream > stream_, int timeout)
Definition: HttpUtil.h:359
std::unique_ptr< wpi::NetworkStream > stream
Definition: HttpUtil.h:364
wpi::raw_socket_istream is
Definition: HttpUtil.h:365
Definition: HttpUtil.h:293
std::string user
Definition: HttpUtil.h:299
std::string url
Definition: HttpUtil.h:298
std::string password
Definition: HttpUtil.h:300
HttpLocation(std::string_view url_, bool *error, std::string *errorMsg)
int port
Definition: HttpUtil.h:302
std::string fragment
Definition: HttpUtil.h:305
std::string host
Definition: HttpUtil.h:301
std::vector< std::pair< std::string, std::string > > params
Definition: HttpUtil.h:304
std::string path
Definition: HttpUtil.h:303
Definition: HttpUtil.h:375
HttpMultipartScanner(std::string_view boundary, bool saveSkipped=false)
Definition: HttpUtil.h:377
void Reset(bool saveSkipped=false)
std::string_view GetSkipped() const
Definition: HttpUtil.h:400
std::string_view Execute(std::string_view in)
bool IsDone() const
Definition: HttpUtil.h:397
void SetBoundary(std::string_view boundary)
Class for HTTP path matching.
Definition: HttpUtil.h:112
bool empty() const
Returns true if the path has no elements.
Definition: HttpUtil.h:133
bool startswith(std::initializer_list< std::string_view > match) const
Returns true if the first elements of the path match the provided match list.
Definition: HttpUtil.h:183
size_t size() const
Returns number of elements in the path.
Definition: HttpUtil.h:138
HttpPathRef drop_front(size_t n) const
Returns a path reference with the first N elements of the path removed.
Definition: HttpUtil.inc:14
bool equals(std::string_view match) const
Definition: HttpUtil.h:152
bool startswith(size_t start, std::string_view match) const
Definition: HttpUtil.h:208
bool equals(size_t start, std::span< const std::string_view > match) const
Definition: HttpUtil.h:166
bool equals(size_t start, std::initializer_list< std::string_view > match) const
Returns true if the elements of the path starting at the "start" element match the provided match lis...
Definition: HttpUtil.h:162
bool startswith(std::string_view match) const
Definition: HttpUtil.h:189
bool equals(std::span< const std::string_view > match) const
Definition: HttpUtil.h:149
bool startswith(size_t start, std::initializer_list< std::string_view > match) const
Returns true if the elements of the path starting at the "start" element match the provided match lis...
Definition: HttpUtil.h:201
bool startswith(std::span< const std::string_view > match) const
Definition: HttpUtil.h:186
bool equals(size_t start, std::string_view match) const
Definition: HttpUtil.h:172
bool startswith(size_t start, std::span< const std::string_view > match) const
HttpPath()=default
Constructs an empty HTTP path.
HttpPath(std::string_view path)
Constructs a HTTP path from an escaped path string.
bool equals(std::initializer_list< std::string_view > match) const
Returns true if the path exactly matches the provided match list.
Definition: HttpUtil.h:146
std::string_view operator[](size_t n) const
Gets a single element of the path.
Proxy reference object for a portion of a HttpPath.
Definition: HttpUtil.h:230
bool empty() const
Definition: HttpUtil.h:238
bool startswith(size_t start, std::initializer_list< std::string_view > match) const
Definition: HttpUtil.h:270
size_t size() const
Definition: HttpUtil.h:239
bool equals(size_t start, std::initializer_list< std::string_view > match) const
Definition: HttpUtil.h:249
bool equals(std::initializer_list< std::string_view > match) const
Definition: HttpUtil.h:241
std::string_view operator[](size_t n) const
Definition: HttpUtil.h:281
bool startswith(size_t start, std::string_view match) const
Definition: HttpUtil.h:277
bool equals(size_t start, std::span< const std::string_view > match) const
Definition: HttpUtil.h:253
bool startswith(std::initializer_list< std::string_view > match) const
Definition: HttpUtil.h:260
bool equals(size_t start, std::string_view match) const
Definition: HttpUtil.h:256
bool startswith(std::string_view match) const
Definition: HttpUtil.h:266
bool startswith(size_t start, std::span< const std::string_view > match) const
Definition: HttpUtil.h:274
HttpPathRef drop_front(size_t n) const
Definition: HttpUtil.h:284
bool equals(std::span< const std::string_view > match) const
Definition: HttpUtil.h:244
bool equals(std::string_view match) const
Definition: HttpUtil.h:247
bool startswith(std::span< const std::string_view > match) const
Definition: HttpUtil.h:263
HttpPathRef(const HttpPath &path, size_t start=0)
Definition: HttpUtil.h:233
Map for looking up elements of the query portion of a URI.
Definition: HttpUtil.h:67
HttpQueryMap()=default
Constructs an empty map (with no entries).
std::optional< std::string_view > Get(std::string_view name, SmallVectorImpl< char > &buf) const
Gets an element of the query string.
HttpQueryMap(std::string_view query)
Constructs from an escaped query string.
Definition: HttpUtil.h:308
HttpRequest(const HttpLocation &loc, std::string_view path_)
Definition: HttpUtil.h:321
HttpRequest(const HttpLocation &loc)
Definition: HttpUtil.h:312
SmallString< 128 > path
Definition: HttpUtil.h:336
HttpRequest(const HttpLocation &loc, std::string_view path_, const T ¶ms)
Definition: HttpUtil.h:327
int port
Definition: HttpUtil.h:334
SmallString< 128 > host
Definition: HttpUtil.h:333
std::string auth
Definition: HttpUtil.h:335
size_t size() const
Definition: SmallVector.h:78
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:81
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMapEntry.h:104
std::string_view getKey() const
Definition: StringMapEntry.h:108
Definition: raw_istream.h:22
bool has_error() const
Definition: raw_istream.h:114
Definition: raw_socket_istream.h:14
Definition: raw_socket_ostream.h:14
basic_string_view< char > string_view
Definition: core.h:520
@ error
Definition: format.h:2559
Definition: StdDeque.h:50
/file This file defines the SmallVector class.
Definition: AprilTagFieldLayout.h:18
bool ParseHttpHeaders(raw_istream &is, SmallVectorImpl< char > *contentType, SmallVectorImpl< char > *contentLength)
std::string_view UnescapeURI(std::string_view str, SmallVectorImpl< char > &buf, bool *error)
bool FindMultipartBoundary(wpi::raw_istream &is, std::string_view boundary, std::string *saveBuf)
std::string_view EscapeURI(std::string_view str, SmallVectorImpl< char > &buf, bool spacePlus=true)