Skip to content

Commit

Permalink
refactor(http): allow body_handler to be NULL
Browse files Browse the repository at this point in the history
If it is NULL, automatic ignore of the HTTP body processing during parse and generate.
  • Loading branch information
Water-Melon committed Apr 25, 2024
1 parent e764241 commit 346091e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/Melon Developer Guide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion docs/book/cn/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion docs/book/en/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion src/mln_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 346091e

Please sign in to comment.