-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample.cpp
More file actions
71 lines (49 loc) · 2.21 KB
/
Copy pathexample.cpp
File metadata and controls
71 lines (49 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include "../src/url_parser.h"
void PrintURL(const std::string& label, const std::string& input_url)
{
std::cout << "=== " << label << " ===" << std::endl;
std::cout << "input:[" << input_url << "]" << std::endl;
URLParser::HTTP_URL http_url = URLParser::Parse(input_url);
std::cout << "scheme:[" << http_url.scheme << "]" << std::endl;
std::cout << "userinfo:[" << http_url.userinfo << "]" << std::endl;
std::cout << "host:[" << http_url.host << "]" << std::endl;
std::cout << "port:[" << http_url.port << "]" << std::endl;
for (const auto& path : http_url.path)
std::cout << "path:[" << path << "]" << std::endl;
std::cout << "query_string:[" << http_url.query_string << "]" << std::endl;
for (const auto& pair : http_url.query)
std::cout << "Query:[" << pair.first << "]:[" << pair.second << "]" << std::endl;
std::cout << "fragment:[" << http_url.fragment << "]" << std::endl;
std::cout << std::endl;
}
int main(void)
{
// Basic: host + port + path + query
PrintURL("Basic", "http://127.0.0.1:40000/path_1/path_2/path_3/foo.git?test=1&test2=3");
// No port
PrintURL("No port", "http://127.0.0.1/path_1/path_2/path_3/foo.git?test=1&test2=3");
// Path only, no query
PrintURL("Path only", "http://127.0.0.1/path_1/path_2/path_3");
// No scheme, with query
PrintURL("No scheme", "/path_1/path_2/path_3/?test=1&test2=3");
// Empty value in query
PrintURL("Empty query value", "https://127.0.0.1:40000/path_1/path_2/path_3/foo.git?test=&test2=3");
// Fragment
PrintURL("Fragment", "http://example.com/docs/page?key=val#section-2");
// Fragment only (no query)
PrintURL("Fragment only", "http://example.com/a#top");
// Userinfo
PrintURL("Userinfo", "http://user:pass@example.com:8080/resource?id=1");
// IPv6
PrintURL("IPv6", "http://[2001:db8::1]:8080/v1/api?debug=true");
// Host only (no path, no query, no fragment)
PrintURL("Host only", "https://example.com");
// Scheme-relative URL
PrintURL("Scheme-relative", "//example.com/path_1/path_2?key=val#frag");
// Scheme-relative with port
PrintURL("Scheme-relative with port", "//example.com:9090/path");
// Scheme-relative with userinfo
PrintURL("Scheme-relative with userinfo", "//user:pass@example.com/path");
return 0;
}