-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathurl.h
69 lines (58 loc) · 1.71 KB
/
url.h
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
/*
* .============.
* // M A K E / \
* // C++ DEV / \
* // E A S Y / \/ \
* ++ ----------. \/\ .
* \\ \ \ /\ /
* \\ \ \ /
* \\ \ \ /
* -============'
*
* Copyright (c) 2018 Hevake and contributors, all rights reserved.
*
* This file is part of cpp-tbox (https://github.com/cpp-main/cpp-tbox)
* Use of this source code is governed by MIT license that can be found
* in the LICENSE file in the root of the source tree. All contributing
* project authors may be found in the CONTRIBUTORS.md file in the root
* of the source tree.
*/
#ifndef TBOX_HTTP_URL_H_20220512
#define TBOX_HTTP_URL_H_20220512
#include <string>
#include <map>
#include <cstdint>
namespace tbox {
namespace http {
/**
* URL格式:<scheme>://<user>:<password>@<host>:<port>/<path>;<params>?<query>#<frag>
*/
struct Url {
std::string scheme;
struct Host {
std::string user;
std::string password;
std::string host;
uint16_t port = 0;
};
struct Path {
using StringMap = std::map<std::string, std::string>;
std::string path;
StringMap params;
StringMap query;
std::string frag;
};
Host host;
Path path;
};
std::string UrlEncode(const std::string &local_str, bool path_mode = false);
std::string UrlDecode(const std::string &url_str);
std::string UrlToString(const Url &url);
std::string UrlHostToString(const Url::Host &host);
std::string UrlPathToString(const Url::Path &path);
bool StringToUrl(const std::string &str, Url &url);
bool StringToUrlHost(const std::string &str, Url::Host &host);
bool StringToUrlPath(const std::string &str, Url::Path &path);
}
}
#endif //TBOX_HTTP_URL_H_20220512