http: fix http server in response 58/40858/2
authorMatus Fabian <matfabia@cisco.com>
Thu, 2 May 2024 09:17:15 +0000 (11:17 +0200)
committerMatus Fabian <matfabia@cisco.com>
Fri, 3 May 2024 06:17:16 +0000 (08:17 +0200)
App name is used in HTTP response Server header.

Type: fix

Change-Id: Ie3b2d985dd7d554a0352f7e602891f878bebd031
Signed-off-by: Matus Fabian <matfabia@cisco.com>
extras/hs-test/hst_suite.go
extras/hs-test/http_test.go
extras/hs-test/script/build_hst.sh
src/plugins/http/http.c
src/plugins/http/http.h

index 4c6d5b2..bb49924 100644 (file)
@@ -149,7 +149,7 @@ func (s *HstSuite) hstFail() {
                out, err := container.log(20)
                if err != nil {
                        fmt.Printf("An error occured while obtaining '%s' container logs: %s\n", container.name, fmt.Sprint(err))
-                       break
+                       continue
                }
                fmt.Printf("\nvvvvvvvvvvvvvvv " +
                        container.name + ":\n" +
index acd026d..fe12f5a 100644 (file)
@@ -13,7 +13,7 @@ func init() {
        registerNsTests(HttpTpsTest)
        registerVethTests(HttpCliTest)
        registerNoTopoTests(NginxHttp3Test, NginxAsServerTest,
-               NginxPerfCpsTest, NginxPerfRpsTest, NginxPerfWrkTest)
+               NginxPerfCpsTest, NginxPerfRpsTest, NginxPerfWrkTest, HeaderServerTest)
        registerNoTopoSoloTests(HttpStaticPromTest)
 }
 
@@ -91,6 +91,21 @@ func HttpStaticPromTest(s *NoTopoSuite) {
        s.assertNil(err)
 }
 
+func HeaderServerTest(s *NoTopoSuite) {
+       query := "show/version"
+       vpp := s.getContainerByName("vpp").vppInstance
+       serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString()
+       vpp.vppctl("http cli server")
+
+       curlCont := s.getContainerByName("curl")
+       args := fmt.Sprintf("curl -i -s http://%s:80/%s", serverAddress, query)
+       curlCont.extraRunningArgs = args
+       o, err := curlCont.combinedOutput()
+       s.assertNil(err, fmt.Sprint(err))
+       s.log(o)
+       s.assertContains(o, "Server: http_cli_server")
+}
+
 func NginxAsServerTest(s *NoTopoSuite) {
        query := "return_ok"
        finished := make(chan error, 1)
index cc2d00b..33a8393 100755 (executable)
@@ -67,9 +67,9 @@ docker_build hs-test/vpp vpp
 docker_build hs-test/nginx-ldp nginx
 docker_build hs-test/nginx-server nginx-server
 docker_build hs-test/build build
+docker_build hs-test/curl curl
 if [ "$HST_EXTENDED_TESTS" = true ] ; then
     docker_build hs-test/nginx-http3 nginx-http3
-    docker_build hs-test/curl curl
 fi
 
 # cleanup detached images
index 0fa113c..37a6de7 100644 (file)
@@ -140,6 +140,7 @@ http_listener_free (http_conn_t *lhc)
 {
   http_main_t *hm = &http_main;
 
+  vec_free (lhc->app_name);
   if (CLIB_DEBUG)
     memset (lhc, 0xfc, sizeof (*lhc));
   pool_put (hm->listener_pool, lhc);
@@ -372,7 +373,7 @@ static const char *http_redirect_template = "HTTP/1.1 %s\r\n";
 static const char *http_response_template = "HTTP/1.1 %s\r\n"
                                            "Date: %U GMT\r\n"
                                            "Expires: %U GMT\r\n"
-                                           "Server: VPP Static\r\n"
+                                           "Server: %s\r\n"
                                            "Content-Type: %s\r\n"
                                            "Content-Length: %lu\r\n\r\n";
 
@@ -734,6 +735,7 @@ http_state_wait_app_reply (http_conn_t *hc, transport_send_params_t *sp)
    * Add headers. For now:
    * - current time
    * - expiration time
+   * - server name
    * - content type
    * - data length
    */
@@ -748,6 +750,8 @@ http_state_wait_app_reply (http_conn_t *hc, transport_send_params_t *sp)
                format_clib_timebase_time, now,
                /* Expires */
                format_clib_timebase_time, now + 600.0,
+               /* Server */
+               hc->app_name,
                /* Content type */
                http_content_type_str[msg.content_type],
                /* Length */
@@ -1199,6 +1203,11 @@ http_start_listen (u32 app_listener_index, transport_endpoint_cfg_t *tep)
   lhc->c_s_index = app_listener_index;
   lhc->c_flags |= TRANSPORT_CONNECTION_F_NO_LOOKUP;
 
+  if (vec_len (app->name))
+    lhc->app_name = vec_dup (app->name);
+  else
+    lhc->app_name = format (0, "VPP server app");
+
   return lhc_index;
 }
 
index dbae5ac..c9912dd 100644 (file)
@@ -227,6 +227,7 @@ typedef struct http_tc_
 
   http_conn_state_t state;
   u32 timer_handle;
+  u8 *app_name;
 
   /*
    * Current request