Skip to content

Commit

Permalink
http/server: add http_set_max_body_size
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Jan 13, 2025
1 parent 11dfeb5 commit f7ba47d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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
21 changes: 20 additions & 1 deletion src/http/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f7ba47d

Please sign in to comment.