From 976beebb5e549eebfe5ab04035163c5fdef0c133 Mon Sep 17 00:00:00 2001 From: Tomer Shalev Date: Thu, 18 Nov 2021 09:27:14 +0200 Subject: [PATCH] Helper functions to print headers --- header.c | 12 ++++++++++++ include/header.h | 2 ++ include/request.h | 2 ++ request.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/header.c b/header.c index eb40a766..e9816211 100644 --- a/header.c +++ b/header.c @@ -707,3 +707,15 @@ int sizeofencaps(ci_encaps_entity_t * e) } return 0; } + +const char *ci_print_icap_headers(ci_headers_list_t *h) +{ + int i; + const char *header; + + ci_debug_printf(1, "\n===== ICAP Headers =====\n"); + for (i = 0; i < h->used; i++) { + header = h->headers[i]; + ci_debug_printf(1, "ICAP header: %s\n", header); + } +} diff --git a/include/header.h b/include/header.h index 1ffe8164..b1549ef8 100644 --- a/include/header.h +++ b/include/header.h @@ -282,6 +282,8 @@ CI_DECLARE_FUNC(const char *) ci_headers_first_line2(ci_headers_list_t *heads, s /*compatibility macro*/ #define ci_headers_copy_header_bytes ci_headers_pack_to_buffer +CI_DECLARE_FUNC(const char *) ci_print_icap_headers(ci_headers_list_t *heads); + /*The following headers are only used internally */ CI_DECLARE_FUNC(void) ci_headers_pack(ci_headers_list_t *heads); CI_DECLARE_FUNC(int) ci_headers_unpack(ci_headers_list_t *heads); diff --git a/include/request.h b/include/request.h index fa57e36c..931483c4 100644 --- a/include/request.h +++ b/include/request.h @@ -271,6 +271,8 @@ CI_DECLARE_FUNC(void) ci_client_library_init(); CI_DECLARE_FUNC(void) ci_client_library_release(); +CI_DECLARE_FUNC(void) ci_print_http_headers(ci_request_t *req); + /** Deprecated. Use ci_connect_to declared in net_io.h instead. */ CI_DECLARE_FUNC(ci_connection_t *) ci_client_connect_to(char *servername,int port,int proto); diff --git a/request.c b/request.c index ab86c17f..52f311e2 100644 --- a/request.c +++ b/request.c @@ -1737,3 +1737,34 @@ int process_request(ci_request_t * req) return res; /*Allow to log even the failed requests*/ } + +void print_http_header(void *d, const char *head, const char *value) +{ + if (!head || !*head) { + ci_debug_printf(1, "\t%s\n", value); + } else { + ci_debug_printf(1, "\t%s: %s\n", head, value); + } +} + +void ci_print_http_headers(ci_request_t *req) +{ + int type; + ci_headers_list_t *headers; + ci_debug_printf(1, "\n===== Request Headers =====\n"); + ci_debug_printf(1, "\nICAP HEADERS:\n"); + ci_headers_iterate(req->response_header, NULL, print_http_header); + ci_debug_printf(1, "\n"); + + if ((headers = ci_http_response_headers(req)) == NULL) { + headers = ci_http_request_headers(req); + type = ICAP_REQMOD; + } else + type = ICAP_RESPMOD; + + if (headers) { + ci_debug_printf(1, "%s HEADERS:\n", ci_method_string(type)); + ci_headers_iterate(headers, NULL, print_http_header); + ci_debug_printf(1, "\n"); + } +}