* [PATCH] Return "404 Not found" if a repo doesn't exist (any more).
@ 2012-12-01 22:02
2013-02-01 11:58 ` Jason
0 siblings, 1 reply; 3+ messages in thread
From: @ 2012-12-01 22:02 UTC (permalink / raw)
If a repository disappears, cgit says "No repositories found" and
returns "200 OK" [to the webcrawler] for pages referring to, say,
commits in the, now, missing repository.
This, slightly awkward, patch makes it return "404 Not found" in this
case. There is probably a better way to do this.
---
ui-repolist.c | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/ui-repolist.c b/ui-repolist.c
index dead1bf..ca65d44 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -247,6 +247,17 @@ void cgit_print_repolist()
if (ctx.cfg.enable_index_links)
columns++;
+ for (i=0; i<cgit_repolist.count; i++) {
+ if (!(is_match(&cgit_repolist.repos[i]) && is_in_url(&cgit_repolist.repos[i])))
+ continue;
+ hits++;
+ }
+
+ if (!hits) {
+ ctx.page.status = 404;
+ ctx.page.statusmsg = "Not found";
+ }
+
ctx.page.title = ctx.cfg.root_title;
cgit_print_http_headers(&ctx);
cgit_print_docstart(&ctx);
--
1.7.2.5
--
"Tell them to give it to Donovan." Adam Sj?gren
asjo at koldfront.dk
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] Return "404 Not found" if a repo doesn't exist (any more).
2012-12-01 22:02 [PATCH] Return "404 Not found" if a repo doesn't exist (any more)
@ 2013-02-01 11:58 ` Jason
2013-02-01 17:48 `
0 siblings, 1 reply; 3+ messages in thread
From: Jason @ 2013-02-01 11:58 UTC (permalink / raw)
On Sat, Dec 1, 2012 at 11:02 PM, Adam Sj?gren <asjo at koldfront.dk> wrote:
> @@ -247,6 +247,17 @@ void cgit_print_repolist()
> if (ctx.cfg.enable_index_links)
> columns++;
>
> + for (i=0; i<cgit_repolist.count; i++) {
> + if (!(is_match(&cgit_repolist.repos[i]) && is_in_url(&cgit_repolist.repos[i])))
> + continue;
> + hits++;
> + }
> +
> + if (!hits) {
> + ctx.page.status = 404;
> + ctx.page.statusmsg = "Not found";
> + }
> +
I like the idea of this, but I hate to duplicate the loop logic like that.
But in fact we do need to know whether there are any hits before
sending headers.
Tricky. I'll see if I can refactor things to be a bit nicer.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Return "404 Not found" if a repo doesn't exist (any more).
2013-02-01 11:58 ` Jason
@ 2013-02-01 17:48 `
0 siblings, 0 replies; 3+ messages in thread
From: @ 2013-02-01 17:48 UTC (permalink / raw)
On Fri, 1 Feb 2013 12:58:25 +0100, Jason wrote:
> On Sat, Dec 1, 2012 at 11:02 PM, Adam Sj?gren <asjo at koldfront.dk> wrote:
>> @@ -247,6 +247,17 @@ void cgit_print_repolist()
>> + for (i=0; i<cgit_repolist.count; i++) {
>> + if (!(is_match(&cgit_repolist.repos[i]) && is_in_url(&cgit_repolist.repos[i])))
>> + continue;
>> + hits++;
>> + }
>> + if (!hits) {
>> + ctx.page.status = 404;
> I like the idea of this, but I hate to duplicate the loop logic like that.
Yeah, that is ugly.
> But in fact we do need to know whether there are any hits before
> sending headers.
That's how far I got...
> Tricky. I'll see if I can refactor things to be a bit nicer.
Sounds great!
Best regards,
Adam
--
"Ge mig en vinterdrog, ge mig allt du har Adam Sj?gren
Kom nu jag ?r kroniskt l?g, bara m?rkret h?rs" asjo at koldfront.dk
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-02-01 17:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-01 22:02 [PATCH] Return "404 Not found" if a repo doesn't exist (any more)
2013-02-01 11:58 ` Jason
2013-02-01 17:48 `
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).