From mboxrd@z Thu Jan 1 00:00:00 1970 From: john at keeping.me.uk (John Keeping) Date: Mon, 11 Aug 2014 22:32:05 +0100 Subject: [PATCH] Handle If-None-Match HTTP header in plain view In-Reply-To: <1407790403-12468-1-git-send-email-damiannohales@gmail.com> References: <1407790403-12468-1-git-send-email-damiannohales@gmail.com> Message-ID: <20140811213205.GD1261@serenity.lan> On Mon, Aug 11, 2014 at 05:53:23PM -0300, Dami?n Nohales wrote: > 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 > --- How does this interact with CGit's cache? What happens if the original page expires from the cache and then a request comes in with a matching Etag? > 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