http_static: api add keepalive-timeout 24/41824/2
authorMatus Fabian <[email protected]>
Tue, 12 Nov 2024 14:48:16 +0000 (15:48 +0100)
committerFlorin Coras <[email protected]>
Wed, 13 Nov 2024 18:09:19 +0000 (18:09 +0000)
Type: improvement

Change-Id: Ia1e0dcf562fd1538794542207ac2cad97d168c6c
Signed-off-by: Matus Fabian <[email protected]>
src/plugins/http_static/http_static.api
src/plugins/http_static/http_static.c
src/plugins/http_static/http_static.h
src/plugins/http_static/http_static_test.c
src/plugins/http_static/static_server.c
test/asf/test_http_static.py

index dd4f513..60c0369 100644 (file)
@@ -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;
index 967b847..464fd27 100644 (file)
@@ -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>
index fac24db..5e0654f 100644 (file)
@@ -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
index f701c8b..edb016f 100644 (file)
@@ -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);
index d1ece75..a37cc3f 100644 (file)
@@ -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))
index 73a95e9..701bfe7 100644 (file)
@@ -50,7 +50,7 @@ class TestHttpStaticVapi(VppAsfTestCase):
         super(TestHttpStaticVapi, cls).tearDownClass()
 
     def test_http_static_vapi(self):
-        self.vapi.http_static_enable(
+        self.vapi.http_static_enable_v3(
             www_root="/tmp",
             uri="tcp://0.0.0.0/80",
         )