about summary refs log tree commit diff stats
path: root/ui-repolist.c
diff options
context:
space:
mode:
authorPeter Colberg2015-12-08 12:53:09 -0500
committerJason A. Donenfeld2016-01-13 17:19:34 +0100
commit9abe4a26a92b91170cb9c5dab830b40fb1e0327f (patch)
treee4f2d5301f9bc4a3bc09ae30b6ff23dd210ed981 /ui-repolist.c
parentui-repolist: extract repo visibility criteria to separate function (diff)
downloadcgit-9abe4a26a92b91170cb9c5dab830b40fb1e0327f.tar.gz
cgit-9abe4a26a92b91170cb9c5dab830b40fb1e0327f.zip
ui-repolist: return HTTP 404 if no repositories found
Return HTTP status code 404 Not found when querying a non-existent
repository, which signals to search engines that a repository no
longer exists. Further, some webservers such as nginx permit
logging requests to different files depending on the HTTP code.

Signed-off-by: Peter Colberg <peter@colberg.org>
Diffstat (limited to 'ui-repolist.c')
-rw-r--r--ui-repolist.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/ui-repolist.c b/ui-repolist.c index 4912fa5..6010a39 100644 --- a/ui-repolist.c +++ b/ui-repolist.c
@@ -115,6 +115,17 @@ static int is_visible(struct cgit_repo *repo)
115 return 1; 115 return 1;
116} 116}
117 117
118static int any_repos_visible(void)
119{
120 int i;
121
122 for (i = 0; i < cgit_repolist.count; i++) {
123 if (is_visible(&cgit_repolist.repos[i]))
124 return 1;
125 }
126 return 0;
127}
128
118static void print_sort_header(const char *title, const char *sort) 129static void print_sort_header(const char *title, const char *sort)
119{ 130{
120 char *currenturl = cgit_currenturl(); 131 char *currenturl = cgit_currenturl();
@@ -266,6 +277,11 @@ void cgit_print_repolist(void)
266 char *section; 277 char *section;
267 int sorted = 0; 278 int sorted = 0;
268 279
280 if (!any_repos_visible()) {
281 cgit_print_error_page(404, "Not found", "No repositories found");
282 return;
283 }
284
269 if (ctx.cfg.enable_index_links) 285 if (ctx.cfg.enable_index_links)
270 ++columns; 286 ++columns;
271 if (ctx.cfg.enable_index_owner) 287 if (ctx.cfg.enable_index_owner)
@@ -347,9 +363,7 @@ void cgit_print_repolist(void)
347 html("</tr>\n"); 363 html("</tr>\n");
348 } 364 }
349 html("</table>"); 365 html("</table>");
350 if (!hits) 366 if (hits > ctx.cfg.max_repo_count)
351 cgit_print_error("No repositories found");
352 else if (hits > ctx.cfg.max_repo_count)
353 print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort); 367 print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort);
354 cgit_print_docend(); 368 cgit_print_docend();
355} 369}