uri_parser.h
Go to the documentation of this file.
1 //
2 // Copyright 2015 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef GRPC_CORE_LIB_URI_URI_PARSER_H
18 #define GRPC_CORE_LIB_URI_URI_PARSER_H
19 
21 
22 #include <map>
23 #include <string>
24 #include <vector>
25 
26 #include "absl/status/statusor.h"
27 #include "absl/strings/string_view.h"
28 
29 namespace grpc_core {
30 
31 class URI {
32  public:
33  struct QueryParam {
36  bool operator==(const QueryParam& other) const {
37  return key == other.key && value == other.value;
38  }
39  bool operator<(const QueryParam& other) const {
40  int c = key.compare(other.key);
41  if (c != 0) return c < 0;
42  return value < other.value;
43  }
44  };
45 
46  // Creates a URI by parsing an rfc3986 URI string. Returns an
47  // InvalidArgumentError on failure.
49  // Creates a URI from components. Returns an InvalidArgumentError on failure.
52  std::vector<QueryParam> query_parameter_pairs, std::string fragment);
53 
54  URI() = default;
55 
56  // Copy construction and assignment
57  URI(const URI& other);
58  URI& operator=(const URI& other);
59  // Move construction and assignment
60  URI(URI&&) = default;
61  URI& operator=(URI&&) = default;
62 
65 
67 
68  const std::string& scheme() const { return scheme_; }
69  const std::string& authority() const { return authority_; }
70  const std::string& path() const { return path_; }
71  // Stores the *last* value appearing for each repeated key in the query
72  // string. If you need to capture repeated query parameters, use
73  // `query_parameter_pairs`.
74  const std::map<absl::string_view, absl::string_view>& query_parameter_map()
75  const {
76  return query_parameter_map_;
77  }
78  // A vector of key:value query parameter pairs, kept in order of appearance
79  // within the URI search string. Repeated keys are represented as separate
80  // key:value elements.
81  const std::vector<QueryParam>& query_parameter_pairs() const {
83  }
84  const std::string& fragment() const { return fragment_; }
85 
86  std::string ToString() const;
87 
88  private:
90  std::vector<QueryParam> query_parameter_pairs, std::string fragment);
91 
95  std::map<absl::string_view, absl::string_view> query_parameter_map_;
96  std::vector<QueryParam> query_parameter_pairs_;
98 };
99 } // namespace grpc_core
100 
101 #endif // GRPC_CORE_LIB_URI_URI_PARSER_H
xds_interop_client.str
str
Definition: xds_interop_client.py:487
grpc_core::URI::PercentDecode
static std::string PercentDecode(absl::string_view str)
Definition: uri_parser.cc:187
grpc_core::URI::URI
URI()=default
grpc_core::URI::query_parameter_pairs_
std::vector< QueryParam > query_parameter_pairs_
Definition: uri_parser.h:96
grpc_core::URI::QueryParam::key
std::string key
Definition: uri_parser.h:34
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::URI::authority_
std::string authority_
Definition: uri_parser.h:93
grpc_core::URI::QueryParam::operator==
bool operator==(const QueryParam &other) const
Definition: uri_parser.h:36
grpc_core::URI::fragment
const std::string & fragment() const
Definition: uri_parser.h:84
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
grpc_core::URI::scheme_
std::string scheme_
Definition: uri_parser.h:92
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_core::URI
Definition: uri_parser.h:31
grpc_core::URI::operator=
URI & operator=(const URI &other)
Definition: uri_parser.cc:324
grpc_core::URI::QueryParam::operator<
bool operator<(const QueryParam &other) const
Definition: uri_parser.h:39
grpc_core::URI::path_
std::string path_
Definition: uri_parser.h:94
grpc_core::URI::Parse
static absl::StatusOr< URI > Parse(absl::string_view uri_text)
Definition: uri_parser.cc:209
grpc_core::URI::QueryParam::value
std::string value
Definition: uri_parser.h:35
grpc_core::URI::path
const std::string & path() const
Definition: uri_parser.h:70
grpc_core::URI::QueryParam
Definition: uri_parser.h:33
grpc_core::URI::authority
const std::string & authority() const
Definition: uri_parser.h:69
grpc_core::URI::query_parameter_map_
std::map< absl::string_view, absl::string_view > query_parameter_map_
Definition: uri_parser.h:95
grpc_core::URI::fragment_
std::string fragment_
Definition: uri_parser.h:97
grpc_core::URI::query_parameter_pairs
const std::vector< QueryParam > & query_parameter_pairs() const
Definition: uri_parser.h:81
grpc_core::URI::scheme
const std::string & scheme() const
Definition: uri_parser.h:68
grpc_core::URI::PercentEncodePath
static std::string PercentEncodePath(absl::string_view str)
Definition: uri_parser.cc:181
grpc_core::URI::Create
static absl::StatusOr< URI > Create(std::string scheme, std::string authority, std::string path, std::vector< QueryParam > query_parameter_pairs, std::string fragment)
Definition: uri_parser.cc:289
grpc_core::URI::PercentEncodeAuthority
static std::string PercentEncodeAuthority(absl::string_view str)
Definition: uri_parser.cc:177
absl::StatusOr
Definition: abseil-cpp/absl/status/statusor.h:187
grpc_core::URI::query_parameter_map
const std::map< absl::string_view, absl::string_view > & query_parameter_map() const
Definition: uri_parser.h:74
grpc_core::URI::ToString
std::string ToString() const
Definition: uri_parser.cc:352
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:47