diff options
author | John Keeping | 2015-08-14 12:47:09 +0100 |
---|---|---|
committer | Jason A. Donenfeld | 2015-08-14 15:46:51 +0200 |
commit | fd00e71ab7cf1eabd8d1fc2e5980055350849034 (patch) | |
tree | 0f206d7e919bcd301f17278fd0e9c37fb2559a12 | |
parent | snapshot: use cgit_print_error_page() for HTTP status codes (diff) | |
download | cgit-fd00e71ab7cf1eabd8d1fc2e5980055350849034.tar.gz cgit-fd00e71ab7cf1eabd8d1fc2e5980055350849034.zip |
snapshot: don't reimplement cgit_print_error_page()
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>
-rw-r--r-- | ui-snapshot.c | 21 |
1 files 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: | |||
180 | return result ? strbuf_detach(&snapshot, NULL) : NULL; | 180 | return result ? strbuf_detach(&snapshot, NULL) : NULL; |
181 | } | 181 | } |
182 | 182 | ||
183 | __attribute__((format (printf, 1, 2))) | ||
184 | static void show_error(char *fmt, ...) | ||
185 | { | ||
186 | va_list ap; | ||
187 | |||
188 | ctx.page.mimetype = "text/html"; | ||
189 | cgit_print_http_headers(); | ||
190 | cgit_print_docstart(); | ||
191 | cgit_print_pageheader(); | ||
192 | va_start(ap, fmt); | ||
193 | cgit_vprint_error(fmt, ap); | ||
194 | va_end(ap); | ||
195 | cgit_print_docend(); | ||
196 | } | ||
197 | |||
198 | void cgit_print_snapshot(const char *head, const char *hex, | 183 | void cgit_print_snapshot(const char *head, const char *hex, |
199 | const char *filename, int dwim) | 184 | const char *filename, int dwim) |
200 | { | 185 | { |
@@ -202,13 +187,15 @@ void cgit_print_snapshot(const char *head, const char *hex, | |||
202 | char *prefix = NULL; | 187 | char *prefix = NULL; |
203 | 188 | ||
204 | if (!filename) { | 189 | if (!filename) { |
205 | show_error("No snapshot name specified"); | 190 | cgit_print_error_page(400, "Bad request", |
191 | "No snapshot name specified"); | ||
206 | return; | 192 | return; |
207 | } | 193 | } |
208 | 194 | ||
209 | f = get_format(filename); | 195 | f = get_format(filename); |
210 | if (!f) { | 196 | if (!f) { |
211 | show_error("Unsupported snapshot format: %s", filename); | 197 | cgit_print_error_page(400, "Bad request", |
198 | "Unsupported snapshot format: %s", filename); | ||
212 | return; | 199 | return; |
213 | } | 200 | } |
214 | 201 | ||