From: Laurent Mazet Date: Tue, 30 May 2023 16:34:06 +0000 (+0200) Subject: manage content-encoding header X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=7fc5f3c63a753acd7d4c9ee3f881d2113075141f;p=webserver.git manage content-encoding header --- diff --git a/http.c b/http.c index fbd18ef..044ab36 100644 --- a/http.c +++ b/http.c @@ -41,10 +41,14 @@ typedef enum { not_supported_e = 0, get_e, head_e, post_e } method_t; +typedef enum { + encoding_plain_e = 0, encoding_gzip_e, encoding_compress_e +} encoding_t; + typedef struct { char *allow; char *authorization; - char *content_encoding; + encoding_t content_encoding; char *content_length; char *content_type; char *date; @@ -112,7 +116,14 @@ void print_header_values (header_t *header) printf ("Header values\n"); if (header->allow) printf ("allow = '%s'\n", header->allow); if (header->authorization) printf ("authorization = '%s'\n", header->authorization); - if (header->content_encoding) printf ("content_encoding = '%s'\n", header->content_encoding); + if (header->content_encoding) { + printf ("content_encoding = "); + switch (header->content_encoding) { + case encoding_plain_e: printf ("plain\n"); break; + case encoding_gzip_e: printf ("gzip\n"); break; + case encoding_compress_e: printf ("compress\n"); break; + } + } if (header->content_length) printf ("content_length = '%s'\n", header->content_length); if (header->content_type) printf ("content_type = '%s'\n", header->content_type); if (header->date) printf ("date = '%s'\n", header->date); @@ -355,8 +366,15 @@ int processing (char *data, int len, conf_t *conf, char **pdata) VERBOSE (DEBUG, PRINT ("Analyse field\n")); if (strcmp (field, "Allow") == 0) { header.allow = value; } else if (strcmp (field, "Authorization") == 0) { header.authorization = value; } - else if (strcmp (field, "Content-Encoding") == 0) { header.content_encoding = value; } - else if (strcmp (field, "Content-Length") == 0) { header.content_length = value; } + else if (strcmp (field, "Content-Encoding") == 0) { + if (strcmp (value, "x-gzip") == 0) { + header.content_encoding = encoding_gzip_e; + } else if (strcmp (value, "x-compress") == 0) { + header.content_encoding = encoding_compress_e; + } else { + VERBOSE (WARNING, PRINT ("Unknown content encoding: %s\n", value)); + } + } else if (strcmp (field, "Content-Length") == 0) { header.content_length = value; } else if (strcmp (field, "Content-Type") == 0) { header.content_type = value; } else if (strcmp (field, "Date") == 0) { header.date = value; } else if (strcmp (field, "Expires") == 0) { header.expires = value; } @@ -379,6 +397,13 @@ int processing (char *data, int len, conf_t *conf, char **pdata) if (len != (header.content_length ? atoi (header.content_length) : 0)) { VERBOSE (WARNING, PRINT ("Incoherent size (%d <> %s)\n", len, header.content_length)); } + if (len > 0) { + switch (header.content_encoding) { + case encoding_plain_e: break; + case encoding_gzip_e: VERBOSE (WARNING, PRINT ("Gzip encoding not supported yet\n")); break; + case encoding_compress_e: VERBOSE (WARNING, PRINT ("Compress encoding not supported yet\n")); break; + } + } /* response */ char *buffer = NULL;