userver: userver/http/url.hpp Source File
Loading...
Searching...
No Matches
url.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/http/url.hpp
4/// @brief URL manipulation functions
5/// @ingroup userver_universal
6
7#include <map>
8#include <string>
9#include <string_view>
10#include <unordered_map>
11
12#include <userver/utils/impl/internal_tag_fwd.hpp>
13#include <userver/utils/str_icase.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace http {
18
19/// @brief Decode URL
20[[deprecated("Use a more strict http::parser::UrlDecode instead")]] std::string
21UrlDecode(std::string_view range);
22
23/// @brief Encode as URL
24std::string UrlEncode(std::string_view input_string);
25
26using Args = std::unordered_map<std::string, std::string, utils::StrCaseHash>;
27using MultiArgs = std::multimap<std::string, std::string>;
28
29/// @brief Make an URL query
30std::string MakeQuery(const Args& query_args);
31
32/// @brief Make an URL query
33std::string MakeQuery(
34 const std::unordered_map<std::string, std::string>& query_args);
35
36/// @brief Make an URL query
37std::string MakeQuery(
38 std::initializer_list<std::pair<std::string_view, std::string_view>>
39 query_args);
40
41/// @brief Make an URL with query arguments
42std::string MakeUrl(std::string_view path, const Args& query_args);
43
44/// @brief Make an URL with query arguments
45std::string MakeUrl(
46 std::string_view path,
47 const std::unordered_map<std::string, std::string>& query_args);
48
49/// @brief Make an URL with query arguments
50std::string MakeUrl(std::string_view path, const Args& query_args,
51 MultiArgs query_multiargs);
52
53/// @brief Make an URL with query arguments
54std::string MakeUrl(
55 std::string_view path,
56 std::initializer_list<std::pair<std::string_view, std::string_view>>
57 query_args);
58
59/// @brief Returns URL part before the first '?' character
60std::string ExtractMetaTypeFromUrl(const std::string& url);
61
62/// @brief Returns HTTP path part of a URL
63std::string ExtractPath(std::string_view url);
64
65/// @brief Returns hostname part of a URL
66std::string ExtractHostname(std::string_view url);
67
68namespace impl {
69
70std::string UrlDecode(utils::impl::InternalTag, std::string_view range);
71
72} // namespace impl
73
74} // namespace http
75
76USERVER_NAMESPACE_END