From mboxrd@z Thu Jan 1 00:00:00 1970 From: damiannohales at gmail.com (=?UTF-8?q?Dami=C3=A1n=20Nohales?=) Date: Mon, 11 Aug 2014 17:53:23 -0300 Subject: [PATCH] Handle If-None-Match HTTP header in plain view Message-ID: <1407790403-12468-1-git-send-email-damiannohales@gmail.com> We are sending Etag to clients but this header is basically unusefulness if the server doesn't tell the client if the content has been changed or not for a given Path/Etag pair. Signed-off-by: Dami?n Nohales --- cgit.c | 1 + cgit.h | 1 + ui-plain.c | 41 +++++++++++++++++++++-------------------- ui-shared.c | 20 ++++++++++++++++++++ ui-shared.h | 1 + 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/cgit.c b/cgit.c index 8c4517d..7af7712 100644 --- a/cgit.c +++ b/cgit.c @@ -385,6 +385,7 @@ static void prepare_context(void) ctx.env.server_port = getenv("SERVER_PORT"); ctx.env.http_cookie = getenv("HTTP_COOKIE"); ctx.env.http_referer = getenv("HTTP_REFERER"); + ctx.env.if_none_match = getenv("HTTP_IF_NONE_MATCH"); ctx.env.content_length = getenv("CONTENT_LENGTH") ? strtoul(getenv("CONTENT_LENGTH"), NULL, 10) : 0; ctx.env.authenticated = 0; ctx.page.mimetype = "text/html"; diff --git a/cgit.h b/cgit.h index 0badc64..eddd4c7 100644 --- a/cgit.h +++ b/cgit.h @@ -282,6 +282,7 @@ struct cgit_environment { const char *server_port; const char *http_cookie; const char *http_referer; + const char *if_none_match; unsigned int content_length; int authenticated; }; diff --git a/ui-plain.c b/ui-plain.c index 30fff89..a08dc5b 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -103,8 +103,8 @@ static int print_object(const unsigned char *sha1, const char *path) ctx.page.filename = path; ctx.page.size = size; ctx.page.etag = sha1_to_hex(sha1); - cgit_print_http_headers(); - html_raw(buf, size); + if (!cgit_print_http_headers_matching_etag()) + html_raw(buf, size); /* If we allocated this, then casting away const is safe. */ if (freemime) free((char*) ctx.page.mimetype); @@ -128,24 +128,25 @@ static void print_dir(const unsigned char *sha1, const char *base, fullpath = buildpath(base, baselen, path); slash = (fullpath[0] == '/' ? "" : "/"); ctx.page.etag = sha1_to_hex(sha1); - cgit_print_http_headers(); - htmlf("%s", slash); - html_txt(fullpath); - htmlf("\n\n

%s", slash); - html_txt(fullpath); - html("

\n