添加从mk_parser循环获取所有header的接口 (#3692)

add mk_api: 添加从mk_parser循环获取所有header的接口
This commit is contained in:
benshi 2024-07-05 20:56:23 +08:00 committed by GitHub
parent 6c3d362b5a
commit fb49515baa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View File

@ -58,6 +58,8 @@ API_EXPORT const char *API_CALL mk_record_info_get_stream(const mk_record_info c
///////////////////////////////////////////Parser/////////////////////////////////////////////
//Parser对象的C映射
typedef struct mk_parser_t *mk_parser;
//Parser对象中Headers foreach回调
typedef void(API_CALL *on_mk_parser_header_cb)(void *user_data, const char *key, const char *val);
//Parser::Method(),获取命令字譬如GET/POST
API_EXPORT const char* API_CALL mk_parser_get_method(const mk_parser ctx);
//Parser::Url(),获取HTTP的访问url(不包括?后面的参数)
@ -72,6 +74,8 @@ API_EXPORT const char* API_CALL mk_parser_get_tail(const mk_parser ctx);
API_EXPORT const char* API_CALL mk_parser_get_header(const mk_parser ctx,const char *key);
//Parser::Content(),获取HTTP body
API_EXPORT const char* API_CALL mk_parser_get_content(const mk_parser ctx, size_t *length);
//循环获取所有header
API_EXPORT void API_CALL mk_parser_headers_for_each(const mk_parser ctx, on_mk_parser_header_cb cb, void *user_data);
///////////////////////////////////////////MediaInfo/////////////////////////////////////////////
//MediaInfo对象的C映射

View File

@ -125,6 +125,13 @@ API_EXPORT const char* API_CALL mk_parser_get_content(const mk_parser ctx, size_
}
return parser->content().c_str();
}
API_EXPORT void API_CALL mk_parser_headers_for_each(const mk_parser ctx, on_mk_parser_header_cb cb, void *user_data){
assert(ctx && cb);
Parser *parser = (Parser *)ctx;
for (auto it = parser->getHeader().begin(); it != parser->getHeader().end(); ++it) {
cb(user_data, it->first.c_str(), it->second.c_str());
}
}
///////////////////////////////////////////MediaInfo/////////////////////////////////////////////
API_EXPORT const char* API_CALL mk_media_info_get_params(const mk_media_info ctx){