mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
http-server: add cli argument for max body size
This commit is contained in:
parent
56e1213109
commit
852af060af
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user