tcp: fix single loop prefetch
[vpp.git] / src / vnet / session-apps / http_server.c
index eeb755b..9ad1297 100644 (file)
@@ -53,6 +53,7 @@ typedef struct
   u32 prealloc_fifos;
   u32 private_segment_size;
   u32 fifo_size;
+  u8 *uri;
   vlib_main_t *vlib_main;
 } http_server_main_t;
 
@@ -86,30 +87,37 @@ free_http_process (http_server_args * args)
   vec_add1 (hsm->free_http_cli_process_node_indices, node_index);
 }
 
-static const char
-  *http_response = "HTTP/1.1 200 OK\r\n"
-  "Content-Type: text/html\r\n"
-  "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n"
-  "Connection: close\r\n"
-  "Pragma: no-cache\r\n" "Content-Length: %d\r\n\r\n%s";
-
-static const char
-  *http_error_template = "HTTP/1.1 %s\r\n"
-  "Content-Type: text/html\r\n"
-  "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n"
-  "Connection: close\r\n" "Pragma: no-cache\r\n" "Content-Length: 0\r\n\r\n";
+/* *INDENT-OFF* */
+static const char *http_response =
+    "HTTP/1.1 200 OK\r\n"
+    "Content-Type: text/html\r\n"
+    "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n"
+    "Connection: keep-alive \r\n"
+    "Pragma: no-cache\r\n"
+    "Content-Length: %d\r\n\r\n%s";
+
+static const char *http_error_template =
+    "HTTP/1.1 %s\r\n"
+    "Content-Type: text/html\r\n"
+    "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n"
+    "Connection: close\r\n"
+    "Pragma: no-cache\r\n"
+    "Content-Length: 0\r\n\r\n";
 
 /* Header, including incantation to suppress favicon.ico requests */
-static const char
-  *html_header_template = "<html><head><title>%v</title>"
-  "</head><link rel=\"icon\" href=\"data:,\"><body><pre>";
-
-static const char *html_footer = "</pre></body></html>\r\n";
-
-static const char
-  *html_header_static = "<html><head><title>static reply</title></head>"
-  "<link rel=\"icon\" href=\"data:,\"><body><pre>hello</pre></body>"
-  "</html>\r\n";
+static const char *html_header_template =
+    "<html><head><title>%v</title></head>"
+    "<link rel=\"icon\" href=\"data:,\">"
+    "<body><pre>";
+
+static const char *html_footer =
+    "</pre></body></html>\r\n";
+
+static const char *html_header_static =
+    "<html><head><title>static reply</title></head>"
+    "<link rel=\"icon\" href=\"data:,\">"
+    "<body><pre>hello</pre></body></html>\r\n";
+/* *INDENT-ON* */
 
 static u8 *static_http;
 
@@ -476,7 +484,7 @@ static session_cb_vft_t http_server_session_cb_vft = {
   .session_disconnect_callback = http_server_session_disconnect_callback,
   .session_connected_callback = http_server_session_connected_callback,
   .add_segment_callback = http_server_add_segment_callback,
-  .builtin_server_rx_callback = http_server_rx_callback,
+  .builtin_app_rx_callback = http_server_rx_callback,
   .session_reset_callback = http_server_session_reset_callback
 };
 
@@ -498,6 +506,8 @@ create_api_loopback (vlib_main_t * vm)
 static int
 server_attach ()
 {
+  vnet_app_add_tls_cert_args_t _a_cert, *a_cert = &_a_cert;
+  vnet_app_add_tls_key_args_t _a_key, *a_key = &_a_key;
   http_server_main_t *hsm = &http_server_main;
   u64 options[APP_OPTIONS_N_OPTIONS];
   vnet_app_attach_args_t _a, *a = &_a;
@@ -526,6 +536,19 @@ server_attach ()
       return -1;
     }
   hsm->app_index = a->app_index;
+
+  memset (a_cert, 0, sizeof (*a_cert));
+  a_cert->app_index = a->app_index;
+  vec_validate (a_cert->cert, test_srv_crt_rsa_len);
+  clib_memcpy (a_cert->cert, test_srv_crt_rsa, test_srv_crt_rsa_len);
+  vnet_app_add_tls_cert (a_cert);
+
+  memset (a_key, 0, sizeof (*a_key));
+  a_key->app_index = a->app_index;
+  vec_validate (a_key->key, test_srv_key_rsa_len);
+  clib_memcpy (a_key->key, test_srv_key_rsa, test_srv_key_rsa_len);
+  vnet_app_add_tls_key (a_key);
+
   return 0;
 }
 
@@ -537,6 +560,8 @@ http_server_listen ()
   memset (a, 0, sizeof (*a));
   a->app_index = hsm->app_index;
   a->uri = "tcp://0.0.0.0/80";
+  if (hsm->uri)
+    a->uri = (char *) hsm->uri;
   return vnet_bind_uri (a);
 }
 
@@ -599,6 +624,8 @@ http_server_create_command_fn (vlib_main_t * vm,
        }
       else if (unformat (input, "fifo-size %d", &hsm->fifo_size))
        hsm->fifo_size <<= 10;
+      else if (unformat (input, "uri %s", &hsm->uri))
+       ;
       else
        return clib_error_return (0, "unknown input `%U'",
                                  format_unformat_error, input);
@@ -610,7 +637,7 @@ http_server_create_command_fn (vlib_main_t * vm,
 
   if (is_static)
     {
-      http_server_session_cb_vft.builtin_server_rx_callback =
+      http_server_session_cb_vft.builtin_app_rx_callback =
        http_server_rx_callback_static;
       html = format (0, html_header_static);
       static_http = format (0, http_response, vec_len (html), html);