summaryrefslogtreecommitdiff
path: root/sample/http-server.c
diff options
context:
space:
mode:
authorAzat Khuzhin <azat@libevent.org>2020-10-04 17:44:34 +0300
committerAzat Khuzhin <azat@libevent.org>2020-10-04 17:44:34 +0300
commit852af060af7c7e439f0db97829ec74bedeba64d5 (patch)
treeb803636c37bd0c18ae5b2169cfa7e97530646fa9 /sample/http-server.c
parent56e121310954cbee2310c5eb2a3000115186563d (diff)
downloadlibevent-852af060af7c7e439f0db97829ec74bedeba64d5.tar.gz
http-server: add cli argument for max body size
Diffstat (limited to 'sample/http-server.c')
-rw-r--r--sample/http-server.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/sample/http-server.c b/sample/http-server.c
index 09d829c6..cf928437 100644
--- a/sample/http-server.c
+++ b/sample/http-server.c
@@ -103,6 +103,7 @@ struct options {
int port;
int iocp;
int verbose;
+ int max_body_size;
int unlink;
const char *unixsock;
@@ -352,6 +353,7 @@ print_usage(FILE *out, const char *prog, int exit_code)
" -U - bind to unix socket\n"
" -u - unlink unix socket before bind\n"
" -I - IOCP\n"
+ " -m - max body size\n"
" -v - verbosity, enables libevent debug logging too\n", prog);
exit(exit_code);
}
@@ -363,12 +365,13 @@ parse_opts(int argc, char **argv)
memset(&o, 0, sizeof(o));
- while ((opt = getopt(argc, argv, "hp:U:uIv")) != -1) {
+ while ((opt = getopt(argc, argv, "hp:U:m:uIv")) != -1) {
switch (opt) {
case 'p': o.port = atoi(optarg); break;
case 'U': o.unixsock = optarg; break;
case 'u': o.unlink = 1; break;
case 'I': o.iocp = 1; break;
+ case 'm': o.max_body_size = atoi(optarg); break;
case 'v': ++o.verbose; break;
case 'h': print_usage(stdout, argv[0], 0); break;
default : fprintf(stderr, "Unknown option %c\n", opt); break;
@@ -507,6 +510,8 @@ main(int argc, char **argv)
/* We want to accept arbitrary requests, so we need to set a "generic"
* cb. We can also add callbacks for specific paths. */
evhttp_set_gencb(http, send_document_cb, &o);
+ if (o.max_body_size)
+ evhttp_set_max_body_size(http, o.max_body_size);
if (o.unixsock) {
#ifdef EVENT__HAVE_STRUCT_SOCKADDR_UN