From 7b7a50e38f3b196571ab2c243f65b4fcc62297a9 Mon Sep 17 00:00:00 2001 From: Hubert Tarasiuk Date: Fri, 27 Mar 2015 14:00:33 +0100 Subject: [PATCH 1/2] Factor out set_content_type function from gethttp * src/http.c (gethttp): Move some code in... (set_content_type): ... a new function. --- src/http.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/http.c b/src/http.c index 53c9818..a127733 100644 --- a/src/http.c +++ b/src/http.c @@ -2330,6 +2330,27 @@ open_output_stream (struct http_stat *hs, int count, FILE **fp) return RETROK; } +/* Set proper type flags based on type string. */ +static void +set_content_type (int *dt, const char *type) +{ + /* If content-type is not given, assume text/html. This is because + o f the multitud*e of broken CGI's that "forget" to generate the + content-type. */ + if (!type || + 0 == strncasecmp (type, TEXTHTML_S, strlen (TEXTHTML_S)) || + 0 == strncasecmp (type, TEXTXHTML_S, strlen (TEXTXHTML_S))) + *dt |= TEXTHTML; + else + *dt &= ~TEXTHTML; + + if (type && + 0 == strncasecmp (type, TEXTCSS_S, strlen (TEXTCSS_S))) + *dt |= TEXTCSS; + else + *dt &= ~TEXTCSS; +} + /* Retrieve a document through HTTP protocol. It recognizes status code, and correctly handles redirections. It closes the network socket. If it receives an error from the functions below it, it @@ -2957,21 +2978,7 @@ read_header: } } - /* If content-type is not given, assume text/html. This is because - of the multitude of broken CGI's that "forget" to generate the - content-type. */ - if (!type || - 0 == strncasecmp (type, TEXTHTML_S, strlen (TEXTHTML_S)) || - 0 == strncasecmp (type, TEXTXHTML_S, strlen (TEXTXHTML_S))) - *dt |= TEXTHTML; - else - *dt &= ~TEXTHTML; - - if (type && - 0 == strncasecmp (type, TEXTCSS_S, strlen (TEXTCSS_S))) - *dt |= TEXTCSS; - else - *dt &= ~TEXTCSS; + set_content_type (dt, type); if (opt.adjust_extension) { -- 2.3.4