3
3
// (See accompanying file LICENSE_1_0.txt or copy at
4
4
// http://www.boost.org/LICENSE_1_0.txt)
5
5
6
- #ifndef __TTP_NETWORK_HTTP_V2_URL_INC__
7
- #define __HTTP_NETWORK_HTTP_V2_URL_INC__
6
+ #ifndef __NETWORK_HTTP_V2_URL_INC__
7
+ #define __NETWORK_HTTP_V2_URL_INC__
8
8
9
9
#include < network/uri.hpp>
10
+ #include < boost/range/algorithm/equal.hpp>
11
+ #include < boost/range/as_literal.hpp>
10
12
11
13
namespace network {
12
14
namespace http {
13
15
namespace v2 {
14
- class invalid_scheme : public std ::runtime_error {
16
+ class scheme_not_http : public std ::runtime_error {
15
17
16
18
public:
17
19
18
- virtual ~invalid_scheme () noexcept {}
19
- virtual const char *what () const noexcept {
20
- return " invalid_scheme" ;
21
- }
20
+ scheme_not_http () : std::runtime_error(" scheme_not_http" ) {}
21
+ virtual ~scheme_not_http () noexcept {}
22
22
23
23
};
24
24
@@ -34,19 +34,25 @@ namespace network {
34
34
35
35
public:
36
36
37
- url () {
38
-
37
+ url () { }
38
+
39
+ template <class Source >
40
+ url (const Source &source)
41
+ : uri_(source) {
42
+ if (auto scheme_ = uri_.scheme ()) {
43
+ if (!boost::equal (boost::as_literal (" http" ), *scheme_) &&
44
+ !boost::equal (boost::as_literal (" https" ), *scheme_) &&
45
+ !boost::equal (boost::as_literal (" shttp" ), *scheme_)) {
46
+ throw scheme_not_http ();
47
+ }
48
+ }
39
49
}
40
50
41
51
url (const url &other)
42
- : uri_(other.uri_) {
52
+ : uri_(other.uri_) { }
43
53
44
- }
45
-
46
- url (url &&other)
47
- : uri_(other.uri_) {
48
-
49
- }
54
+ url (url &&other) noexcept
55
+ : uri_(std::move(other.uri_)) { }
50
56
51
57
url &operator = (url other) {
52
58
other.swap (*this );
@@ -65,6 +71,38 @@ namespace network {
65
71
return uri_.end ();
66
72
}
67
73
74
+ boost::optional<string_view> user_info () const {
75
+ return uri_.user_info ();
76
+ }
77
+
78
+ boost::optional<string_view> host () const {
79
+ return uri_.host ();
80
+ }
81
+
82
+ boost::optional<string_view> port () const {
83
+ return uri_.port ();
84
+ }
85
+
86
+ boost::optional<string_view> path () const {
87
+ return uri_.path ();
88
+ }
89
+
90
+ boost::optional<string_view> query () const {
91
+ return uri_.query ();
92
+ }
93
+
94
+ boost::optional<string_view> fragment () const {
95
+ return uri_.fragment ();
96
+ }
97
+
98
+ boost::optional<string_view> authority () const {
99
+ return uri_.authority ();
100
+ }
101
+
102
+ std::string string () const {
103
+ return uri_.string ();
104
+ }
105
+
68
106
bool empty () const noexcept {
69
107
return uri_.empty ();
70
108
}
@@ -73,6 +111,31 @@ namespace network {
73
111
return uri_.is_absolute ();
74
112
}
75
113
114
+ url normalize (uri_comparison_level level) const {
115
+ return url (uri_.normalize (level));
116
+ // if scheme-specific
117
+ // normalize query arguments in alphanumeric order
118
+ }
119
+
120
+ url make_reference (const url &other, uri_comparison_level level) const {
121
+ return url (uri_.make_reference (other.uri_ , level));
122
+ }
123
+
124
+ url resolve (const url &other, uri_comparison_level level) const {
125
+ return url (uri_.resolve (other.uri_ , level));
126
+ }
127
+
128
+ int compare (const url &other, uri_comparison_level level) const noexcept {
129
+ int result = uri_.compare (other.uri_ , level);
130
+ // if result == 0 and scheme-specific
131
+ // compare query arguments
132
+ return result;
133
+ }
134
+
135
+ uri to_uri () const {
136
+ return uri_;
137
+ }
138
+
76
139
private:
77
140
78
141
uri uri_;
@@ -82,5 +145,4 @@ namespace network {
82
145
} // namespace http
83
146
} // namespace network
84
147
85
-
86
- #endif // __HTTP_NETWORK_HTTP_V2_URL_INC__
148
+ #endif // __NETWORK_HTTP_V2_URL_INC__
0 commit comments