2019-07-28 10:31:56 +08:00
|
|
|
|
#pragma once
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../acl_cpp_define.hpp"
|
2021-06-08 16:45:49 +08:00
|
|
|
|
#include "../stdlib/string.hpp"
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
2024-07-22 17:07:57 +08:00
|
|
|
|
class ACL_CPP_API http_utils {
|
2014-11-19 00:25:21 +08:00
|
|
|
|
public:
|
|
|
|
|
http_utils() {}
|
|
|
|
|
~http_utils() {}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> url <EFBFBD>л<EFBFBD><EFBFBD><EFBFBD> WEB <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>domain:port
|
|
|
|
|
* @param url {const char*} HTTP url<EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>
|
|
|
|
|
* @param addr {char*} <EFBFBD>洢<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>洢<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>domain:port
|
|
|
|
|
* @param size {size_t} out <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
|
|
|
|
* @return {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
static bool get_addr(const char* url, char* addr, size_t size);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> url <EFBFBD>л<EFBFBD><EFBFBD><EFBFBD> WEB <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP <EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>˿ں<EFBFBD>
|
|
|
|
|
* @param url {const char*} HTTP url<EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>
|
|
|
|
|
* @param domain {char*} <EFBFBD>洢<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param size {size_t} domain <EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>С
|
|
|
|
|
* @param port {unsigned short*} <EFBFBD>洢<EFBFBD>˿ںŴ<EFBFBD>С
|
|
|
|
|
* @return {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
static bool get_addr(const char* url, char* domain, size_t size,
|
|
|
|
|
unsigned short* port);
|
2021-06-08 16:45:49 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ACL_CPP_API http_url {
|
|
|
|
|
public:
|
2024-07-22 17:07:57 +08:00
|
|
|
|
http_url();
|
|
|
|
|
~http_url() {}
|
2021-06-08 16:45:49 +08:00
|
|
|
|
|
|
|
|
|
bool parse(const char* url);
|
|
|
|
|
|
|
|
|
|
public:
|
2021-07-06 15:11:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> URL <EFBFBD>е<EFBFBD>Э<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>http <EFBFBD><EFBFBD> https
|
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
2024-07-22 17:07:57 +08:00
|
|
|
|
const char* get_proto() const {
|
2021-06-08 16:45:49 +08:00
|
|
|
|
return proto_;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 15:11:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> URL <EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
|
|
|
|
|
* @return {const char*} <EFBFBD><EFBFBD><EFBFBD>ؿմ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾû<EFBFBD>и<EFBFBD><EFBFBD>ֶ<EFBFBD>
|
|
|
|
|
*/
|
2024-07-22 17:07:57 +08:00
|
|
|
|
const char* get_domain() const {
|
2021-06-08 16:45:49 +08:00
|
|
|
|
return domain_.c_str();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 15:11:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD> URL <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD> HTTP Э<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶˿ںţ<EFBFBD><EFBFBD>ڲ<EFBFBD>ȱʡֵΪ 80
|
|
|
|
|
* @return {unsigned short}
|
|
|
|
|
*/
|
2024-07-22 17:07:57 +08:00
|
|
|
|
unsigned short get_port() const {
|
2021-06-08 16:45:49 +08:00
|
|
|
|
return port_;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 15:11:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD> URL <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ? <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
2024-07-22 17:07:57 +08:00
|
|
|
|
const char* get_url_path() const {
|
2021-06-08 16:45:49 +08:00
|
|
|
|
return url_path_.c_str();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 15:11:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD> URL <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
|
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
2024-07-22 17:07:57 +08:00
|
|
|
|
const char* get_url_params() const {
|
2021-06-08 16:45:49 +08:00
|
|
|
|
return url_params_.c_str();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 15:11:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>м<EFBFBD>״̬<EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>ظ<EFBFBD>ʹ<EFBFBD>ø<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> URL
|
|
|
|
|
*/
|
2024-07-22 17:07:57 +08:00
|
|
|
|
void reset();
|
2021-06-08 16:45:49 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
char proto_[16];
|
|
|
|
|
string domain_;
|
|
|
|
|
unsigned short port_;
|
|
|
|
|
string url_path_;
|
|
|
|
|
string url_params_;
|
|
|
|
|
|
|
|
|
|
bool parse_url_part(const char* url);
|
|
|
|
|
const char* parse_domain(const char* url);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|