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 port;
|
||||||
int iocp;
|
int iocp;
|
||||||
int verbose;
|
int verbose;
|
||||||
|
int max_body_size;
|
||||||
|
|
||||||
int unlink;
|
int unlink;
|
||||||
const char *unixsock;
|
const char *unixsock;
|
||||||
@ -352,6 +353,7 @@ print_usage(FILE *out, const char *prog, int exit_code)
|
|||||||
" -U - bind to unix socket\n"
|
" -U - bind to unix socket\n"
|
||||||
" -u - unlink unix socket before bind\n"
|
" -u - unlink unix socket before bind\n"
|
||||||
" -I - IOCP\n"
|
" -I - IOCP\n"
|
||||||
|
" -m - max body size\n"
|
||||||
" -v - verbosity, enables libevent debug logging too\n", prog);
|
" -v - verbosity, enables libevent debug logging too\n", prog);
|
||||||
exit(exit_code);
|
exit(exit_code);
|
||||||
}
|
}
|
||||||
@ -363,12 +365,13 @@ parse_opts(int argc, char **argv)
|
|||||||
|
|
||||||
memset(&o, 0, sizeof(o));
|
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) {
|
switch (opt) {
|
||||||
case 'p': o.port = atoi(optarg); break;
|
case 'p': o.port = atoi(optarg); break;
|
||||||
case 'U': o.unixsock = optarg; break;
|
case 'U': o.unixsock = optarg; break;
|
||||||
case 'u': o.unlink = 1; break;
|
case 'u': o.unlink = 1; break;
|
||||||
case 'I': o.iocp = 1; break;
|
case 'I': o.iocp = 1; break;
|
||||||
|
case 'm': o.max_body_size = atoi(optarg); break;
|
||||||
case 'v': ++o.verbose; break;
|
case 'v': ++o.verbose; break;
|
||||||
case 'h': print_usage(stdout, argv[0], 0); break;
|
case 'h': print_usage(stdout, argv[0], 0); break;
|
||||||
default : fprintf(stderr, "Unknown option %c\n", opt); 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"
|
/* We want to accept arbitrary requests, so we need to set a "generic"
|
||||||
* cb. We can also add callbacks for specific paths. */
|
* cb. We can also add callbacks for specific paths. */
|
||||||
evhttp_set_gencb(http, send_document_cb, &o);
|
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) {
|
if (o.unixsock) {
|
||||||
#ifdef EVENT__HAVE_STRUCT_SOCKADDR_UN
|
#ifdef EVENT__HAVE_STRUCT_SOCKADDR_UN
|
||||||
|
Loading…
x
Reference in New Issue
Block a user