aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/http_static
diff options
context:
space:
mode:
authorMatus Fabian <matfabia@cisco.com>2024-11-12 15:48:16 +0100
committerFlorin Coras <florin.coras@gmail.com>2024-11-13 18:09:19 +0000
commita4597a74aad03b707a69ab4670ca594efc59caa0 (patch)
treea490d400ac77c5cb1986c4eabcc1524f2cd1c2ea /src/plugins/http_static
parent942e3d583c448f6b632a09f15a250b6804304a0d (diff)
http_static: api add keepalive-timeout
Type: improvement Change-Id: Ia1e0dcf562fd1538794542207ac2cad97d168c6c Signed-off-by: Matus Fabian <matfabia@cisco.com>
Diffstat (limited to 'src/plugins/http_static')
-rw-r--r--src/plugins/http_static/http_static.api12
-rw-r--r--src/plugins/http_static/http_static.c22
-rw-r--r--src/plugins/http_static/http_static.h1
-rw-r--r--src/plugins/http_static/http_static_test.c24
-rw-r--r--src/plugins/http_static/static_server.c2
5 files changed, 38 insertions, 23 deletions
diff --git a/src/plugins/http_static/http_static.api b/src/plugins/http_static/http_static.api
index dd4f513a420..60c0369848d 100644
--- a/src/plugins/http_static/http_static.api
+++ b/src/plugins/http_static/http_static.api
@@ -3,20 +3,21 @@
This file defines static http server control-plane API messages
*/
-option version = "2.2.0";
+option version = "2.3.0";
/** \brief Configure and enable the static http server
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@param fifo_size - size (in bytes) of the session FIFOs
@param cache_size_limit - size (in bytes) of the in-memory file data cache
+ @param max_age - how long a response is considered fresh (in seconds)
@param prealloc_fifos - number of preallocated fifos (usually 0)
@param private_segment_size - fifo segment size (usually 0)
@param www_root - html root path
@param uri - bind URI, defaults to "tcp://0.0.0.0/80"
*/
-autoreply define http_static_enable {
+autoreply define http_static_enable_v2 {
option deprecated;
/* Client identifier, set from api_main.my_client_index */
@@ -27,6 +28,7 @@ autoreply define http_static_enable {
/* Typical options */
u32 fifo_size;
u32 cache_size_limit;
+ u32 max_age [default=600];
/* Unusual options */
u32 prealloc_fifos;
u32 private_segment_size;
@@ -43,13 +45,16 @@ autoreply define http_static_enable {
@param fifo_size - size (in bytes) of the session FIFOs
@param cache_size_limit - size (in bytes) of the in-memory file data cache
@param max_age - how long a response is considered fresh (in seconds)
+ @param keepalive_timeout - timeout during which client connection will stay open (in seconds)
@param prealloc_fifos - number of preallocated fifos (usually 0)
@param private_segment_size - fifo segment size (usually 0)
@param www_root - html root path
@param uri - bind URI, defaults to "tcp://0.0.0.0/80"
*/
-autoreply define http_static_enable_v2 {
+autoreply define http_static_enable_v3 {
+ option deprecated;
+
/* Client identifier, set from api_main.my_client_index */
u32 client_index;
@@ -59,6 +64,7 @@ autoreply define http_static_enable_v2 {
u32 fifo_size;
u32 cache_size_limit;
u32 max_age [default=600];
+ u32 keepalive_timeout [default=60];
/* Unusual options */
u32 prealloc_fifos;
u32 private_segment_size;
diff --git a/src/plugins/http_static/http_static.c b/src/plugins/http_static/http_static.c
index 967b8474af8..464fd27e90d 100644
--- a/src/plugins/http_static/http_static.c
+++ b/src/plugins/http_static/http_static.c
@@ -66,7 +66,8 @@ hss_register_url_handler (hss_url_handler_fn fp, const char *url,
*/
static int
hss_enable_api (u32 fifo_size, u32 cache_limit, u32 prealloc_fifos,
- u32 private_segment_size, u8 *www_root, u8 *uri, u32 max_age)
+ u32 private_segment_size, u8 *www_root, u8 *uri, u32 max_age,
+ u32 keepalive_timeout)
{
hss_main_t *hsm = &hss_main;
int rv;
@@ -78,6 +79,7 @@ hss_enable_api (u32 fifo_size, u32 cache_limit, u32 prealloc_fifos,
hsm->www_root = format (0, "%s%c", www_root, 0);
hsm->uri = format (0, "%s%c", uri, 0);
hsm->max_age = max_age;
+ hsm->keepalive_timeout = keepalive_timeout;
if (vec_len (hsm->www_root) < 2)
return VNET_API_ERROR_INVALID_VALUE;
@@ -104,10 +106,10 @@ hss_enable_api (u32 fifo_size, u32 cache_limit, u32 prealloc_fifos,
}
/* API message handler */
-static void vl_api_http_static_enable_t_handler
- (vl_api_http_static_enable_t * mp)
+static void
+vl_api_http_static_enable_v2_t_handler (vl_api_http_static_enable_v2_t *mp)
{
- vl_api_http_static_enable_reply_t *rmp;
+ vl_api_http_static_enable_v2_reply_t *rmp;
hss_main_t *hsm = &hss_main;
int rv;
@@ -117,16 +119,16 @@ static void vl_api_http_static_enable_t_handler
rv = hss_enable_api (ntohl (mp->fifo_size), ntohl (mp->cache_size_limit),
ntohl (mp->prealloc_fifos),
ntohl (mp->private_segment_size), mp->www_root, mp->uri,
- HSS_DEFAULT_MAX_AGE);
+ ntohl (mp->max_age), HSS_DEFAULT_KEEPALIVE_TIMEOUT);
- REPLY_MACRO (VL_API_HTTP_STATIC_ENABLE_REPLY);
+ REPLY_MACRO (VL_API_HTTP_STATIC_ENABLE_V2_REPLY);
}
/* API message handler */
static void
-vl_api_http_static_enable_v2_t_handler (vl_api_http_static_enable_v2_t *mp)
+vl_api_http_static_enable_v3_t_handler (vl_api_http_static_enable_v3_t *mp)
{
- vl_api_http_static_enable_v2_reply_t *rmp;
+ vl_api_http_static_enable_v3_reply_t *rmp;
hss_main_t *hsm = &hss_main;
int rv;
@@ -136,9 +138,9 @@ vl_api_http_static_enable_v2_t_handler (vl_api_http_static_enable_v2_t *mp)
rv = hss_enable_api (ntohl (mp->fifo_size), ntohl (mp->cache_size_limit),
ntohl (mp->prealloc_fifos),
ntohl (mp->private_segment_size), mp->www_root, mp->uri,
- ntohl (mp->max_age));
+ ntohl (mp->max_age), ntohl (mp->keepalive_timeout));
- REPLY_MACRO (VL_API_HTTP_STATIC_ENABLE_V2_REPLY);
+ REPLY_MACRO (VL_API_HTTP_STATIC_ENABLE_V3_REPLY);
}
#include <http_static/http_static.api.c>
diff --git a/src/plugins/http_static/http_static.h b/src/plugins/http_static/http_static.h
index fac24db4ec9..5e0654fae24 100644
--- a/src/plugins/http_static/http_static.h
+++ b/src/plugins/http_static/http_static.h
@@ -24,6 +24,7 @@
#include <http_static/http_cache.h>
#define HSS_DEFAULT_MAX_AGE 600
+#define HSS_DEFAULT_KEEPALIVE_TIMEOUT 60
/** @file http_static.h
* Static http server definitions
diff --git a/src/plugins/http_static/http_static_test.c b/src/plugins/http_static/http_static_test.c
index f701c8b9ee7..edb016f9e05 100644
--- a/src/plugins/http_static/http_static_test.c
+++ b/src/plugins/http_static/http_static_test.c
@@ -39,10 +39,10 @@ http_static_test_main_t http_static_test_main;
#include <vlibapi/vat_helper_macros.h>
static int
-api_http_static_enable (vat_main_t * vam)
+api_http_static_enable_v2 (vat_main_t *vam)
{
unformat_input_t *line_input = vam->input;
- vl_api_http_static_enable_t *mp;
+ vl_api_http_static_enable_v2_t *mp;
u64 tmp;
u8 *www_root = 0;
u8 *uri = 0;
@@ -50,6 +50,7 @@ api_http_static_enable (vat_main_t * vam)
u32 private_segment_size = 0;
u32 fifo_size = 8 << 10;
u32 cache_size_limit = 1 << 20;
+ u32 max_age = HSS_DEFAULT_MAX_AGE;
int ret;
/* Parse args required to build the message */
@@ -89,7 +90,8 @@ api_http_static_enable (vat_main_t * vam)
}
cache_size_limit = (u32) tmp;
}
-
+ else if (unformat (line_input, "max-age %d", &max_age))
+ ;
else if (unformat (line_input, "uri %s", &uri))
;
else
@@ -108,16 +110,15 @@ api_http_static_enable (vat_main_t * vam)
if (uri == 0)
uri = format (0, "tcp://0.0.0.0/80%c", 0);
-
-
/* Construct the API message */
- M (HTTP_STATIC_ENABLE, mp);
+ M (HTTP_STATIC_ENABLE_V2, mp);
strncpy_s ((char *) mp->www_root, 256, (const char *) www_root, 256);
strncpy_s ((char *) mp->uri, 256, (const char *) uri, 256);
mp->fifo_size = ntohl (fifo_size);
mp->cache_size_limit = ntohl (cache_size_limit);
mp->prealloc_fifos = ntohl (prealloc_fifos);
mp->private_segment_size = ntohl (private_segment_size);
+ mp->max_age = ntohl (max_age);
/* send it... */
S (mp);
@@ -128,10 +129,10 @@ api_http_static_enable (vat_main_t * vam)
}
static int
-api_http_static_enable_v2 (vat_main_t *vam)
+api_http_static_enable_v3 (vat_main_t *vam)
{
unformat_input_t *line_input = vam->input;
- vl_api_http_static_enable_v2_t *mp;
+ vl_api_http_static_enable_v3_t *mp;
u64 tmp;
u8 *www_root = 0;
u8 *uri = 0;
@@ -140,6 +141,7 @@ api_http_static_enable_v2 (vat_main_t *vam)
u32 fifo_size = 8 << 10;
u32 cache_size_limit = 1 << 20;
u32 max_age = HSS_DEFAULT_MAX_AGE;
+ u32 keepalive_timeout = HSS_DEFAULT_KEEPALIVE_TIMEOUT;
int ret;
/* Parse args required to build the message */
@@ -181,6 +183,9 @@ api_http_static_enable_v2 (vat_main_t *vam)
}
else if (unformat (line_input, "max-age %d", &max_age))
;
+ else if (unformat (line_input, "keepalive-timeout %d",
+ &keepalive_timeout))
+ ;
else if (unformat (line_input, "uri %s", &uri))
;
else
@@ -200,7 +205,7 @@ api_http_static_enable_v2 (vat_main_t *vam)
uri = format (0, "tcp://0.0.0.0/80%c", 0);
/* Construct the API message */
- M (HTTP_STATIC_ENABLE_V2, mp);
+ M (HTTP_STATIC_ENABLE_V3, mp);
strncpy_s ((char *) mp->www_root, 256, (const char *) www_root, 256);
strncpy_s ((char *) mp->uri, 256, (const char *) uri, 256);
mp->fifo_size = ntohl (fifo_size);
@@ -208,6 +213,7 @@ api_http_static_enable_v2 (vat_main_t *vam)
mp->prealloc_fifos = ntohl (prealloc_fifos);
mp->private_segment_size = ntohl (private_segment_size);
mp->max_age = ntohl (max_age);
+ mp->keepalive_timeout = ntohl (keepalive_timeout);
/* send it... */
S (mp);
diff --git a/src/plugins/http_static/static_server.c b/src/plugins/http_static/static_server.c
index d1ece75ce37..a37cc3f03b2 100644
--- a/src/plugins/http_static/static_server.c
+++ b/src/plugins/http_static/static_server.c
@@ -902,7 +902,7 @@ hss_create_command_fn (vlib_main_t *vm, unformat_input_t *input,
hsm->fifo_size = 0;
hsm->cache_size = 10 << 20;
hsm->max_age = HSS_DEFAULT_MAX_AGE;
- hsm->keepalive_timeout = 60;
+ hsm->keepalive_timeout = HSS_DEFAULT_KEEPALIVE_TIMEOUT;
/* Get a line of input. */
if (!unformat_user (input, unformat_line_input, line_input))