diff --git a/api/include/mk_events_objects.h b/api/include/mk_events_objects.h index 5d1127a3..f81cbe61 100644 --- a/api/include/mk_events_objects.h +++ b/api/include/mk_events_objects.h @@ -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映射 diff --git a/api/source/mk_events_objects.cpp b/api/source/mk_events_objects.cpp index 097e4201..46bc408e 100644 --- a/api/source/mk_events_objects.cpp +++ b/api/source/mk_events_objects.cpp @@ -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){