]> granicus.if.org Git - libevent/commitdiff
http-server: add cli argument for max body size
authorAzat Khuzhin <azat@libevent.org>
Sun, 4 Oct 2020 14:44:34 +0000 (17:44 +0300)
committerAzat Khuzhin <azat@libevent.org>
Sun, 4 Oct 2020 14:44:34 +0000 (17:44 +0300)
sample/http-server.c

index 09d829c62b473bc6c944d0cd2fe93f94ba5e6dbd..cf92843790d7bb83d398f0d873c7243ad5ae60f3 100644 (file)
@@ -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