负责Http字符串和URL解析 包括从 URL 或请求报文中提取参数、IP、端口、请求头字段等功能。 更多...
#include <sttnet.h>
静态 Public 成员函数 | |
| static size_t | get_split_str (const std::string_view &ori_str, std::string_view &str, const std::string_view &a, const std::string_view &b, const size_t &pos=0) |
| 从原始字符串中提取两个标记之间的子串。 更多... | |
| static std::string_view & | get_value_str (const std::string_view &ori_str, std::string_view &str, const std::string &name) |
| 从 URL 查询参数中提取指定 key 的值。 更多... | |
| static std::string_view & | get_value_header (const std::string_view &ori_str, std::string_view &str, const std::string &name) |
| 从 HTTP 请求头中提取指定字段的值。 更多... | |
| static std::string_view & | get_location_str (const std::string_view &ori_str, std::string_view &str) |
| 提取 URL 中 path 和 query 部分。 更多... | |
| static std::string_view & | getLocPara (const std::string_view &url, std::string_view &locPara) |
| 提取 URL 的 path 部分(不含 query)。 更多... | |
| static std::string_view & | getPara (const std::string_view &url, std::string_view ¶) |
| 获取 URL 中的查询参数字符串(包括 ?)。 更多... | |
| static size_t | get_split_str (const std::string_view &ori_str, std::string &str, const std::string_view &a, const std::string_view &b, const size_t &pos=0) |
| 从原始字符串中提取两个标记之间的子串。 更多... | |
| static std::string & | get_value_str (const std::string &ori_str, std::string &str, const std::string &name) |
| 从 URL 查询参数中提取指定 key 的值。 更多... | |
| static std::string & | get_value_header (const std::string &ori_str, std::string &str, const std::string &name) |
| 从 HTTP 请求头中提取指定字段的值。 更多... | |
| static std::string & | get_location_str (const std::string &ori_str, std::string &str) |
| 提取 URL 中 path 和 query 部分。 更多... | |
| static std::string & | getLocPara (const std::string &url, std::string &locPara) |
| 提取 URL 的 path 部分(不含 query)。 更多... | |
| static std::string & | getPara (const std::string &url, std::string ¶) |
| 获取 URL 中的查询参数字符串(包括 ?)。 更多... | |
| static std::string & | getIP (const std::string &url, std::string &IP) |
| 从 URL 中提取主机 IP 或域名。 更多... | |
| static int & | getPort (const std::string &url, int &port) |
| 从 URL 中提取端口号。 更多... | |
| static std::string | createHeader (const std::string &first, const std::string &second) |
| 创建一个 HTTP 请求头字段字符串。 更多... | |
| template<class... Args> | |
| static std::string | createHeader (const std::string &first, const std::string &second, Args...args) |
| 递归构造多个 HTTP 请求头字段。 更多... | |
负责Http字符串和URL解析 包括从 URL 或请求报文中提取参数、IP、端口、请求头字段等功能。
|
static |
创建一个 HTTP 请求头字段字符串。
该函数构造格式为 字段名: 字段值\r\n 的字符串。
| first | 第一个字段名。 |
| second | 第一个字段值。 |
|
inlinestatic |
递归构造多个 HTTP 请求头字段。
支持多个字段名和值的构造,用法为:
最终生成:
| Args | 其余参数,需以 (字段名, 字段值) 成对传入。 |
| first | 当前字段名。 |
| second | 当前字段值。 |
| args | 后续的字段名和值(必须为偶数个)。 |
|
static |
提取 URL 中 path 和 query 部分。
例如从 http://abc.com/path?query=123 或者从/path?query=123 提取 /path。
| ori_str | 原始 URL。 |
| str | 返回 path 部分。 |
|
static |
提取 URL 中 path 和 query 部分。
例如从 http://abc.com/path?query=123 或者从/path?query=123 提取 /path。
| ori_str | 原始 URL。 |
| str | 返回 path 部分。 |
|
static |
从原始字符串中提取两个标记之间的子串。
提取从 a 到 b 之间的内容(不包含 a 和 b),可指定起始搜索位置。 若 a 或 b 为空字符串,则分别表示从头或到尾。 若a找不到,则默认从头开始 若b找不到,则默认到尾
| ori_str | 原始字符串。 |
| str | 存储提取结果的字符串。 |
| a | 起始标记字符串。 |
| b | 终止标记字符串。 |
| pos | 搜索起始位置。 |
|
static |
从原始字符串中提取两个标记之间的子串。
提取从 a 到 b 之间的内容(不包含 a 和 b),可指定起始搜索位置。 若 a 或 b 为空字符串,则分别表示从头或到尾。 若a找不到,则默认从头开始 若b找不到,则默认到尾
| ori_str | 原始字符串。 |
| str | 存储提取结果的字符串。 |
| a | 起始标记字符串。 |
| b | 终止标记字符串。 |
| pos | 搜索起始位置。 |
|
static |
从 HTTP 请求头中提取指定字段的值。
| ori_str | 原始 HTTP 请求头字符串。 |
| str | 提取结果。 |
| name | 请求头字段名(如 "Host")。 |
|
static |
从 HTTP 请求头中提取指定字段的值。
| ori_str | 原始 HTTP 请求头字符串。 |
| str | 提取结果。 |
| name | 请求头字段名(如 "Host")。 |
|
static |
从 URL 查询参数中提取指定 key 的值。
?id=123&name=abc提取 id 的值和从http://xxxx/?id=123&name=abc提取 id 的值是一样的。| ori_str | 原始 URL 字符串。 |
| str | 存储提取结果的字符串。 |
| name | 参数名(key)。 |
|
static |
从 URL 查询参数中提取指定 key 的值。
?id=123&name=abc提取 id 的值和从http://xxxx/?id=123&name=abc提取 id 的值是一样的。| ori_str | 原始 URL 字符串。 |
| str | 存储提取结果的字符串。 |
| name | 参数名(key)。 |
|
static |
从 URL 中提取主机 IP 或域名。
例如从 http://127.0.0.1:8080/ 提取 127.0.0.1。
| url | 完整 URL。 |
| IP | 存储提取的 IP 或域名。 |
|
static |
提取 URL 的 path 部分(不含 query)。
与 get_location_str 类似,但保留 path 之后的所有内容(如参数)。
| URL。 | |
| locPara | 返回 path+参数部分。 |
|
static |
提取 URL 的 path 部分(不含 query)。
与 get_location_str 类似,但保留 path 之后的所有内容(如参数)。
| URL。 | |
| locPara | 返回 path+参数部分。 |
|
static |
获取 URL 中的查询参数字符串(包括 ?)。
| URL。 | |
| para | 返回参数部分(形如 "?id=123&name=abc")。 |
|
static |
获取 URL 中的查询参数字符串(包括 ?)。
| URL。 | |
| para | 返回参数部分(形如 "?id=123&name=abc")。 |
|
static |
从 URL 中提取端口号。
例如从 http://127.0.0.1:8080/ 中提取 8080。
| url | 完整 URL。 |
| port | 存储解析出的端口号。 |
1.8.5