aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/hs_apps/http_client.c24
-rw-r--r--src/vnet/session/application_interface.c91
-rw-r--r--src/vnet/session/application_interface.h1
3 files changed, 103 insertions, 13 deletions
diff --git a/src/plugins/hs_apps/http_client.c b/src/plugins/hs_apps/http_client.c
index e4759317cbe..4701253bf59 100644
--- a/src/plugins/hs_apps/http_client.c
+++ b/src/plugins/hs_apps/http_client.c
@@ -693,9 +693,9 @@ hc_get_event (vlib_main_t *vm)
{
wrk = hc_worker_get (hcm->worker_index);
hc_session = hc_session_get (wrk->session_index, wrk->thread_index);
- vlib_cli_output (vm, "< %v< %v", hc_session->response_status,
- hc_session->resp_headers);
- vlib_cli_output (vm, "\n%v\n", hc_session->http_response);
+ vlib_cli_output (vm, "< %v\n< %v\n%v", hc_session->response_status,
+ hc_session->resp_headers,
+ hc_session->http_response);
}
break;
case HC_REPEAT_DONE:
@@ -851,8 +851,6 @@ hc_command_fn (vlib_main_t *vm, unformat_input_t *input,
;
else if (unformat (line_input, "data %v", &hcm->data))
hcm->is_file = 0;
- else if (unformat (line_input, "target %s", &hcm->target))
- ;
else if (unformat (line_input, "file %s", &path))
hcm->is_file = 1;
else if (unformat (line_input, "use-ptr"))
@@ -919,11 +917,7 @@ hc_command_fn (vlib_main_t *vm, unformat_input_t *input,
err = clib_error_return (0, "URI not defined");
goto done;
}
- if (!hcm->target)
- {
- err = clib_error_return (0, "target not defined");
- goto done;
- }
+
if (!hcm->data && hcm->req_method == HTTP_REQ_POST)
{
if (path)
@@ -939,6 +933,7 @@ hc_command_fn (vlib_main_t *vm, unformat_input_t *input,
goto done;
}
}
+
if (hcm->duration && hcm->repeat_count)
{
err = clib_error_return (
@@ -953,6 +948,13 @@ hc_command_fn (vlib_main_t *vm, unformat_input_t *input,
goto done;
}
+ if ((rv = parse_target ((char **) &hcm->uri, (char **) &hcm->target)))
+ {
+ err = clib_error_return (0, "target parse error: %U",
+ format_session_error, rv);
+ goto done;
+ }
+
if ((rv = parse_uri ((char *) hcm->uri, &hcm->connect_sep)))
{
err =
@@ -1000,7 +1002,7 @@ done:
VLIB_CLI_COMMAND (hc_command, static) = {
.path = "http client",
.short_help =
- "[post] uri http://<ip-addr> target <origin-form> "
+ "[post] uri http://<ip-addr>/<origin-form> "
"[data <form-urlencoded> | file <file-path>] [use-ptr] "
"[save-to <filename>] [header <Key:Value>] [verbose] "
"[timeout <seconds> (default = 10)] [repeat <count> | duration <seconds>] "
diff --git a/src/vnet/session/application_interface.c b/src/vnet/session/application_interface.c
index a62f914d43a..e2f9a6883fe 100644
--- a/src/vnet/session/application_interface.c
+++ b/src/vnet/session/application_interface.c
@@ -38,12 +38,12 @@
*
*/
uword
-unformat_vnet_uri (unformat_input_t * input, va_list * args)
+unformat_vnet_uri (unformat_input_t *input, va_list *args)
{
session_endpoint_cfg_t *sep = va_arg (*args, session_endpoint_cfg_t *);
u32 transport_proto = 0, port;
- if (unformat (input, "%U://%U/%d", unformat_transport_proto,
+ if (unformat (input, "%U://%U:%d", unformat_transport_proto,
&transport_proto, unformat_ip4_address, &sep->ip.ip4, &port))
{
sep->transport_proto = transport_proto;
@@ -52,6 +52,54 @@ unformat_vnet_uri (unformat_input_t * input, va_list * args)
return 1;
}
else if (unformat (input, "%U://%U/%d", unformat_transport_proto,
+ &transport_proto, unformat_ip4_address, &sep->ip.ip4,
+ &port))
+ {
+ sep->transport_proto = transport_proto;
+ sep->port = clib_host_to_net_u16 (port);
+ sep->is_ip4 = 1;
+ return 1;
+ }
+ else if (unformat (input, "%U://%U", unformat_transport_proto,
+ &transport_proto, unformat_ip4_address, &sep->ip.ip4))
+ {
+ sep->transport_proto = transport_proto;
+ if (sep->transport_proto == TRANSPORT_PROTO_HTTP)
+ port = 80;
+ else if (sep->transport_proto == TRANSPORT_PROTO_TLS)
+ port = 443;
+ else
+ return 0;
+
+ sep->port = clib_host_to_net_u16 (port);
+ sep->is_ip4 = 1;
+ return 1;
+ }
+ else if (unformat (input, "%U://[%U]:%d", unformat_transport_proto,
+ &transport_proto, unformat_ip6_address, &sep->ip.ip6,
+ &port))
+ {
+ sep->transport_proto = transport_proto;
+ sep->port = clib_host_to_net_u16 (port);
+ sep->is_ip4 = 0;
+ return 1;
+ }
+ else if (unformat (input, "%U://[%U]", unformat_transport_proto,
+ &transport_proto, unformat_ip6_address, &sep->ip.ip6))
+ {
+ sep->transport_proto = transport_proto;
+ if (sep->transport_proto == TRANSPORT_PROTO_HTTP)
+ port = 80;
+ else if (sep->transport_proto == TRANSPORT_PROTO_TLS)
+ port = 443;
+ else
+ return 0;
+
+ sep->port = clib_host_to_net_u16 (port);
+ sep->is_ip4 = 0;
+ return 1;
+ }
+ else if (unformat (input, "%U://%U/%d", unformat_transport_proto,
&transport_proto, unformat_ip6_address, &sep->ip.ip6,
&port))
{
@@ -106,6 +154,45 @@ parse_uri (char *uri, session_endpoint_cfg_t *sep)
return 0;
}
+/* Use before 'parse_uri()'. Removes target from URI and copies it to 'char
+ * **target'. char **target is resized automatically.
+ */
+session_error_t
+parse_target (char **uri, char **target)
+{
+ u8 counter = 0;
+
+ for (u32 i = 0; i < (u32) strlen (*uri); i++)
+ {
+ if ((*uri)[i] == '/')
+ counter++;
+
+ if (counter == 3)
+ {
+ /* resize and make space for NULL terminator */
+ if (vec_len (*target) < strlen (*uri) - i + 2)
+ vec_resize (*target, strlen (*uri) - i + 2);
+
+ strncpy (*target, *uri + i, strlen (*uri) - i);
+ (*uri)[i + 1] = '\0';
+ break;
+ }
+ }
+
+ if (!*target)
+ {
+ vec_resize (*target, 2);
+ **target = '/';
+ }
+
+ vec_terminate_c_string (*target);
+
+ if (!*target)
+ return SESSION_E_INVALID;
+
+ return 0;
+}
+
session_error_t
vnet_bind_uri (vnet_listen_args_t *a)
{
diff --git a/src/vnet/session/application_interface.h b/src/vnet/session/application_interface.h
index 21ed97998f2..33b61187fe3 100644
--- a/src/vnet/session/application_interface.h
+++ b/src/vnet/session/application_interface.h
@@ -281,6 +281,7 @@ typedef enum session_fd_flag_
} session_fd_flag_t;
session_error_t parse_uri (char *uri, session_endpoint_cfg_t *sep);
+session_error_t parse_target (char **uri, char **target);
session_error_t vnet_bind_uri (vnet_listen_args_t *);
session_error_t vnet_unbind_uri (vnet_unlisten_args_t *a);
session_error_t vnet_connect_uri (vnet_connect_args_t *a);