[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cgit
Subject:    [PATCH v2 09/22] snapshot: don't reimplement cgit_print_error_page()
From:       John Keeping <john () keeping ! me ! uk>
Date:       2015-08-14 11:47:09
Message-ID: 9ebef8be25649ab9b72dbc57627351c7e49b19b1.1439552492.git.john () keeping ! me ! uk
[Download RAW message or body]

cgit_print_error_page() has the advantage that it sets a suitable HTTP
status code for the response.  Note that setting "mimetype" is redundant
here since it cannot have changed since being initialized in
cgit.c::prepare_context(), so we do not need to worry that
cgit_print_error_page() does not set it.

Signed-off-by: John Keeping <john@keeping.me.uk>
---
 ui-snapshot.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/ui-snapshot.c b/ui-snapshot.c
index 9bcf13d..f68e877 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -180,21 +180,6 @@ out:
 	return result ? strbuf_detach(&snapshot, NULL) : NULL;
 }
 
-__attribute__((format (printf, 1, 2)))
-static void show_error(char *fmt, ...)
-{
-	va_list ap;
-
-	ctx.page.mimetype = "text/html";
-	cgit_print_http_headers();
-	cgit_print_docstart();
-	cgit_print_pageheader();
-	va_start(ap, fmt);
-	cgit_vprint_error(fmt, ap);
-	va_end(ap);
-	cgit_print_docend();
-}
-
 void cgit_print_snapshot(const char *head, const char *hex,
 			 const char *filename, int dwim)
 {
@@ -202,13 +187,15 @@ void cgit_print_snapshot(const char *head, const char *hex,
 	char *prefix = NULL;
 
 	if (!filename) {
-		show_error("No snapshot name specified");
+		cgit_print_error_page(400, "Bad request",
+				"No snapshot name specified");
 		return;
 	}
 
 	f = get_format(filename);
 	if (!f) {
-		show_error("Unsupported snapshot format: %s", filename);
+		cgit_print_error_page(400, "Bad request",
+				"Unsupported snapshot format: %s", filename);
 		return;
 	}
 
-- 
2.5.0.466.g9af26fa

_______________________________________________
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic