From: Florin Coras Date: Sat, 21 Jun 2025 02:04:43 +0000 (-0700) Subject: http_static: improve cli short help X-Git-Tag: v26.02-rc0~224 X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=f84494d29b776bf1fa4c4ab435794aa1a705482c;p=vpp.git http_static: improve cli short help - make sure all params are present in both create and add/del listener - rename max-body-size to max-req-body-size as it should be easier to glean the purpose of the config Type: refactor Change-Id: I0f30eebe0b001e48ff640552396087e5da35334d Signed-off-by: Florin Coras --- diff --git a/src/plugins/http_static/http_static.c b/src/plugins/http_static/http_static.c index 85b044fb860..91168570c2e 100644 --- a/src/plugins/http_static/http_static.c +++ b/src/plugins/http_static/http_static.c @@ -80,7 +80,7 @@ hss_enable_api (u32 fifo_size, u32 cache_limit, u32 prealloc_fifos, hsm->default_listener.www_root = format (0, "%s%c", www_root, 0); hsm->default_listener.cache_size = cache_limit; hsm->default_listener.max_age = max_age; - hsm->default_listener.max_body_size = max_body_size; + hsm->default_listener.max_req_body_size = max_body_size; hsm->default_listener.rx_buff_thresh = rx_buff_thresh; hsm->default_listener.keepalive_timeout = keepalive_timeout; hsm->have_default_listener = 1; diff --git a/src/plugins/http_static/http_static.h b/src/plugins/http_static/http_static.h index 46c9e758844..b5407de6415 100644 --- a/src/plugins/http_static/http_static.h +++ b/src/plugins/http_static/http_static.h @@ -160,7 +160,7 @@ typedef struct hss_listener_ /** Max cache size before LRU occurs */ u64 cache_size; /** Maximum size of a request body (in bytes) **/ - u64 max_body_size; + u64 max_req_body_size; /** Maximum size of a large memory allocation */ u32 rx_buff_thresh; /** Timeout during which client connection will stay open */ diff --git a/src/plugins/http_static/static_server.c b/src/plugins/http_static/static_server.c index 4015916bcfe..25606ec96a8 100644 --- a/src/plugins/http_static/static_server.c +++ b/src/plugins/http_static/static_server.c @@ -597,7 +597,7 @@ handle_request (hss_session_t *hs) l = hss_listener_get (hs->listener_index); - if (hs->left_recv > l->max_body_size) + if (hs->left_recv > l->max_req_body_size) { start_send_data (hs, HTTP_STATUS_CONTENT_TOO_LARGE); hss_session_disconnect_transport (hs); @@ -1129,7 +1129,7 @@ hss_create_command_fn (vlib_main_t *vm, unformat_input_t *input, l->cache_size = 10 << 20; l->max_age = HSS_DEFAULT_MAX_AGE; - l->max_body_size = HSS_DEFAULT_MAX_BODY_SIZE; + l->max_req_body_size = HSS_DEFAULT_MAX_BODY_SIZE; l->rx_buff_thresh = HSS_DEFAULT_RX_BUFFER_THRESH; l->keepalive_timeout = HSS_DEFAULT_KEEPALIVE_TIMEOUT; l->flags = 0; @@ -1166,8 +1166,8 @@ hss_create_command_fn (vlib_main_t *vm, unformat_input_t *input, ; else if (unformat (line_input, "max-age %d", &l->max_age)) ; - else if (unformat (line_input, "max-body-size %U", unformat_memory_size, - &l->max_body_size)) + else if (unformat (line_input, "max-req-body-size %U", + unformat_memory_size, &l->max_req_body_size)) ; else if (unformat (line_input, "rx-buff-thresh %U", unformat_memory_size, &l->rx_buff_thresh)) @@ -1180,6 +1180,10 @@ hss_create_command_fn (vlib_main_t *vm, unformat_input_t *input, ; else if (unformat (line_input, "http1-only")) l->flags |= HSS_LISTENER_F_HTTP1_ONLY; + /* Deprecated */ + else if (unformat (line_input, "max-body-size %U", unformat_memory_size, + &l->max_req_body_size)) + ; else { error = clib_error_return (0, "unknown input `%U'", @@ -1233,23 +1237,24 @@ done: * Enable the static http server * * @cliexpar - * This command enables the static http server. Only the www-root - * parameter is required + * This command enables the static http server. Listeners can be added later * @clistart * http static server www-root /tmp/www uri tcp://0.0.0.0/80 cache-size 2m * @cliend - * @cliexcmd{http static server www-root [url-handlers] - * [private-segment-size ] [fifo-size ] [max-age ] - * [uri ] [ptr-thresh ] [prealloc-fifos ] [debug [nn]] - * [keepalive-timeout ] [max-body-size ] [http1-only]} + * @cliexcmd{http static server [private-segment-size ] + * [fifo-size ] [prealloc-fifos ] [debug ] [uri ] + * [www-root ] [url-handlers] [cache-size ] [max-age ] + * [max-req-body-size ] [rx-buff-thresh ] [keepalive-timeout ] + * [ptr-thresh ] [http1-only]} ?*/ VLIB_CLI_COMMAND (hss_create_command, static) = { .path = "http static server", .short_help = - "http static server [www-root ] [url-handlers]\n" - "[private-segment-size ] [fifo-size ] [max-age ]\n" - "[uri ] [ptr-thresh ] [prealloc-fifos ] [debug [nn]]\n" - "[keepalive-timeout ] [max-body-size ] [http1-only]\n", + "http static server [private-segment-size ] [fifo-size ]\n" + "[prealloc-fifos ] [debug ] [uri ] [www-root ]\n" + "[url-handlers] [cache-size ] [max-age ]\n" + "[max-req-body-size ] [rx-buff-thresh ] [keepalive-timeout ]\n" + "[ptr-thresh ] [http1-only]\n", .function = hss_create_command_fn, }; @@ -1272,7 +1277,7 @@ hss_add_del_listener_command_fn (vlib_main_t *vm, unformat_input_t *input, l->cache_size = 10 << 20; l->max_age = HSS_DEFAULT_MAX_AGE; - l->max_body_size = HSS_DEFAULT_MAX_BODY_SIZE; + l->max_req_body_size = HSS_DEFAULT_MAX_BODY_SIZE; l->rx_buff_thresh = HSS_DEFAULT_RX_BUFFER_THRESH; l->keepalive_timeout = HSS_DEFAULT_KEEPALIVE_TIMEOUT; l->flags = 0; @@ -1292,19 +1297,25 @@ hss_add_del_listener_command_fn (vlib_main_t *vm, unformat_input_t *input, else if (unformat (line_input, "cache-size %U", unformat_memory_size, &l->cache_size)) ; + else if (unformat (line_input, "max-age %d", &l->max_age)) + ; + else if (unformat (line_input, "max-req-body-size %U", + unformat_memory_size, &l->max_req_body_size)) + ; + else if (unformat (line_input, "rx-buff-thresh %U", unformat_memory_size, + &l->rx_buff_thresh)) + ; else if (unformat (line_input, "keepalive-timeout %d", &l->keepalive_timeout)) ; else if (unformat (line_input, "ptr-thresh %U", unformat_memory_size, &l->use_ptr_thresh)) ; - else if (unformat (line_input, "max-age %d", &l->max_age)) - ; + else if (unformat (line_input, "http1-only")) + l->flags |= HSS_LISTENER_F_HTTP1_ONLY; + /* Deprecated */ else if (unformat (line_input, "max-body-size %U", unformat_memory_size, - &l->max_body_size)) - ; - else if (unformat (line_input, "rx-buff-thresh %U", unformat_memory_size, - &l->rx_buff_thresh)) + &l->max_req_body_size)) ; else { @@ -1357,10 +1368,28 @@ done: return error; } +/*? + * Add static http server listener + * + * @cliexpar + * Add a static http server listener. The listener can be used to + * serve static files from the www-root directory or to handle + * requests using url handlers. + * @clistart + * http static listener www-root /tmp/www uri tcp://0.0.0.0/80 cache-size 2m + * @cliend + * @cliexcmd{http static listener [uri ] [www-root ] [url-handlers] + * [cache-size ] [max-age ] [max-req-body-size ] + * [rx-buff-thresh ] [keepalive-timeout ] [ptr-thresh ] + * [http1-only]} +?*/ VLIB_CLI_COMMAND (hss_add_del_listener_command, static) = { .path = "http static listener", - .short_help = "http static listener [add|del] uri \n" - "[www-root ] [url-handlers] [http1-only]\n", + .short_help = + "http static listener [add|del] [uri ] [www-root ]\n" + "[url-handlers] [cache-size ] [max-age ]\n" + "[max-req-body-size ] [rx-buff-thresh ] [keepalive-timeout ]\n" + "[ptr-thresh ] [http1-only]\n", .function = hss_add_del_listener_command_fn, };