Blob Blame History Raw
From 8047207b470ea417b11919e84931a751485d2326 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Fri, 10 Mar 2017 12:11:12 +0100
Subject: [PATCH 79/90] tcurl test: allow to set custom headers

Reviewed-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
(cherry picked from commit d1ed11fc50922aab2332758a9300f3fbf814f112)
---
 src/tests/tcurl_test_tool.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/tests/tcurl_test_tool.c b/src/tests/tcurl_test_tool.c
index 4ceef8e06040ea0abd4d112a5b7845f436c69488..63a3e26b561781795873c2a4d72ac071a4da9939 100644
--- a/src/tests/tcurl_test_tool.c
+++ b/src/tests/tcurl_test_tool.c
@@ -40,6 +40,7 @@ struct tool_options {
     int tls;
     int verify_peer;
     int verify_host;
+    const char **headers;
 
     enum tcurl_http_method method;
     const char *socket_path;
@@ -121,13 +122,14 @@ prepare_requests(TALLOC_CTX *mem_ctx,
                  size_t *_num_requests)
 {
     struct tcurl_request **requests;
+    struct sss_iobuf *body;
+    const char **headers;
     const char *arg;
     const char *url;
-    struct sss_iobuf *body;
     errno_t ret;
     size_t i;
 
-    static const char *headers[] = {
+    static const char *default_headers[] = {
         "Content-type: application/octet-stream",
         NULL,
     };
@@ -137,6 +139,8 @@ prepare_requests(TALLOC_CTX *mem_ctx,
         return ENOMEM;
     }
 
+    headers = opts->headers == NULL ? default_headers : opts->headers;
+
     i = 0;
     while ((arg = poptGetArg(pc)) != NULL) {
         if (i >= MAXREQ) {
@@ -302,6 +306,9 @@ int main(int argc, const char *argv[])
         { "put", 'p', POPT_ARG_NONE, NULL, 'p', "Perform a HTTP PUT", NULL },
         { "post", 'o', POPT_ARG_NONE, NULL, 'o', "Perform a HTTP POST", NULL },
         { "del", 'd', POPT_ARG_NONE, NULL, 'd', "Perform a HTTP DELETE", NULL },
+#ifdef POPT_ARG_ARGV
+        { "header", 'h', POPT_ARG_ARGV, &opts.headers, '\0', "Add HTTP header", NULL },
+#endif
         { "raw", 'r', POPT_ARG_NONE, &opts.raw, '\0', "Print raw protocol output", NULL },
         { "verbose", 'v', POPT_ARG_NONE, &opts.verbose, '\0', "Print response code and body", NULL },
         /* TLS */
-- 
2.9.3