[PATCH 00/17] HTTP response code improvements
John Keeping
john at keeping.me.uk
Sun Apr 5 18:28:16 CEST 2015
On Sun, Apr 05, 2015 at 04:54:46PM +0100, John Keeping wrote:
> Following Nicolas' report[0] about CGit caching error pages I've been
> looking into ways of (optionally) avoiding caching error responses.
>
> This series doesn't achieve that but it does give us two features that
> will help to do so (neither of which are the case without this series of
> patches):
>
> 1) Always return an HTTP error code if something goes wrong
> 2) Always set "ctx.page.status" when returning an error page
The change to avoid caching errors is quite simple on top of this
series:
-- >8 --
diff --git a/cache.c b/cache.c
index cd99812..be41467 100644
--- a/cache.c
+++ b/cache.c
@@ -261,6 +261,7 @@ unsigned long hash_str(const char *str)
static int process_slot(struct cache_slot *slot)
{
int err;
+ int use_new_slot;
err = open_slot(slot);
if (!err && slot->match) {
@@ -333,7 +334,8 @@ static int process_slot(struct cache_slot *slot)
// Lets avoid such a race by just printing the content of
// the lock file.
slot->cache_fd = slot->lock_fd;
- unlock_slot(slot, 1);
+ use_new_slot = !ctx.page.status || ctx.page.status == 200;
+ unlock_slot(slot, use_new_slot);
if ((err = print_slot(slot)) != 0) {
cache_log("[cgit] error printing cache %s: %s (%d)\n",
slot->cache_name,
-- 8< --
But I think we probably want something a bit more configurable than that
since there are some errors that users might want to cache.
More information about the CGit
mailing list