Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http/server: increase BUFSIZE_MAX to 1 MB and add http_set_max_body_size #1262

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/re_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ int https_listen(struct http_sock **sockp, const struct sa *laddr,
const char *cert, http_req_h *reqh, void *arg);
int https_set_verify_msgh(struct http_sock *sock,
https_verify_msg_h *verifyh);
void http_set_max_body_size(struct http_sock *sock, size_t limit);
struct tcp_sock *http_sock_tcp(struct http_sock *sock);
struct tls *http_sock_tls(const struct http_sock *conn);
const struct sa *http_conn_peer(const struct http_conn *conn);
Expand Down
23 changes: 21 additions & 2 deletions src/http/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
enum {
TIMEOUT_IDLE = 600000,
TIMEOUT_INIT = 10000,
BUFSIZE_MAX = 524288,
BUFSIZE_MAX = 1024 * 1024 * 1, /* 1 MB */
};

struct http_sock {
Expand All @@ -31,6 +31,7 @@ struct http_sock {
struct tls *tls;
http_req_h *reqh;
https_verify_msg_h *verifyh;
size_t max_body_size;
void *arg;
};

Expand Down Expand Up @@ -212,7 +213,8 @@ static void recv_handler(struct mbuf *mb, void *arg)

const size_t len = mbuf_get_left(mb), pos = conn->mb->pos;

if ((mbuf_get_left(conn->mb) + len) > BUFSIZE_MAX) {
if ((mbuf_get_left(conn->mb) + len) >
conn->sock->max_body_size) {
err = EOVERFLOW;
goto out;
}
Expand Down Expand Up @@ -376,6 +378,7 @@ int http_listen_fd(struct http_sock **sockp, re_sock_t fd, http_req_h *reqh,

sock->reqh = reqh;
sock->arg = arg;
sock->max_body_size = BUFSIZE_MAX;

out:
if (err)
Expand Down Expand Up @@ -416,6 +419,7 @@ int http_listen(struct http_sock **sockp, const struct sa *laddr,

sock->reqh = reqh;
sock->arg = arg;
sock->max_body_size = BUFSIZE_MAX;

out:
if (err)
Expand Down Expand Up @@ -496,6 +500,21 @@ int https_set_verify_msgh(struct http_sock *sock,
}


/**
* Set Request buffer size limit
*
* @param sock HTTP socket
* @param limit New limit in bytes
*/
void http_set_max_body_size(struct http_sock *sock, size_t limit)
{
if (!sock)
return;

sock->max_body_size = limit;
}


/**
* Get the TCP socket of an HTTP socket
*
Expand Down
2 changes: 2 additions & 0 deletions test/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ static int test_http_loop_base(bool secure, const char *met, bool http_conn,
if (err)
goto out;

http_set_max_body_size(sock, 1024 * 1024 / 2);

err = tcp_sock_local_get(http_sock_tcp(sock), &srv);
if (err)
goto out;
Expand Down
Loading