diff --git a/docs/Melon Developer Guide.txt b/docs/Melon Developer Guide.txt index 01659d1..d167e0f 100644 --- a/docs/Melon Developer Guide.txt +++ b/docs/Melon Developer Guide.txt @@ -1412,7 +1412,7 @@ Their definitions can be found in melon/include/mln_types.h. a) mln_http_t *mln_http_init(mln_tcp_conn_t *connection, void *data, mln_http_handler body_handler); Initialize a HTTP object. 'body_handler' is a callback handler. When we call mln_http_parse() or mln_http_generate(), this function - will be called to process HTTP body. + will be called to process HTTP body if it is not `NULL`. 'data' is a user data. It will be passed to 'body_handler'. b) void mln_http_destroy(mln_http_t *http); diff --git a/docs/book/cn/http.md b/docs/book/cn/http.md index 5ba61a6..c40a013 100644 --- a/docs/book/cn/http.md +++ b/docs/book/cn/http.md @@ -28,7 +28,7 @@ mln_http_t *mln_http_init(mln_tcp_conn_t *connection, void *data, mln_http_handl typedef int (*mln_http_handler)(mln_http_t *, mln_chain_t **, mln_chain_t **); ``` -描述:创建并初始化`mln_http_t`结构。`connection`是TCP结构,内含TCP套接字。`data`为体处理函数的用户自定义数据部分,用于辅助请求或响应体的处理。`body_handler`是体处理函数,该函数会在每次调用`mln_http_parse`或`mln_http_generate`函数时被调用。体处理函数有三个参数,分别为:http结构,用于解析或生成HTTP报文的双向链表的头和尾节点。 +描述:创建并初始化`mln_http_t`结构。`connection`是TCP结构,内含TCP套接字。`data`为体处理函数的用户自定义数据部分,用于辅助请求或响应体的处理。`body_handler`是体处理函数,如果该指针非`NULL`,则该函数会在每次调用`mln_http_parse`或`mln_http_generate`函数时被调用。体处理函数有三个参数,分别为:http结构,用于解析或生成HTTP报文的双向链表的头和尾节点。 返回值:成功则返回`mln_http_t`结构指针,否则返回`NULL` diff --git a/docs/book/en/http.md b/docs/book/en/http.md index 228da7b..6553acf 100644 --- a/docs/book/en/http.md +++ b/docs/book/en/http.md @@ -28,7 +28,7 @@ mln_http_t *mln_http_init(mln_tcp_conn_t *connection, void *data, mln_http_handl typedef int (*mln_http_handler)(mln_http_t *, mln_chain_t **, mln_chain_t **); ``` -Description: Create and initialize the `mln_http_t` structure. `connection` is a TCP structure, which contains a TCP socket. `data` is the user-defined data part of the body processing function, which is used to assist the processing of the request or response body. `body_handler` is the body handler function, which is called every time the `mln_http_parse` or `mln_http_generate` function is called. The body processing function has three parameters: http structure, the head and tail nodes of the doubly linked list used to parse or generate HTTP packets. +Description: Create and initialize the `mln_http_t` structure. `connection` is a TCP structure, which contains a TCP socket. `data` is the user-defined data part of the body processing function, which is used to assist the processing of the request or response body. `body_handler` is the body handler function, which is called every time the `mln_http_parse` or `mln_http_generate` function is called if it is not `NULL`. The body processing function has three parameters: http structure, the head and tail nodes of the doubly linked list used to parse or generate HTTP packets. Return value: return `mln_http_t` structure pointer if successful, otherwise return `NULL` diff --git a/src/mln_http.c b/src/mln_http.c index 0248da0..695ac9c 100644 --- a/src/mln_http.c +++ b/src/mln_http.c @@ -133,7 +133,7 @@ MLN_FUNC(, int, mln_http_parse, (mln_http_t *http, mln_chain_t **in), (http, in) } if (ret == M_HTTP_RET_OK || ret == M_HTTP_RET_ERROR) return ret; - ret = handler(http, in, NULL); + if (handler != NULL) ret = handler(http, in, NULL); if (ret == M_HTTP_RET_DONE) { mln_http_done_set(http, 0); }