aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Lars Hjemli <hjemli@gmail.com>2008-03-24 08:51:19 (JST)
committerGravatar Lars Hjemli <hjemli@gmail.com>2008-03-24 08:51:19 (JST)
commitf3c1a187fe2bc33f8423cd535d5045899699995b (patch)
treeb5c553da7b108900535fcfcd24b78bdd0ac62387
parentb1f9b9c1459cb9a30ebf80721aff6ef788d1f891 (diff)
downloadcgit-f3c1a187fe2bc33f8423cd535d5045899699995b.zip
cgit-f3c1a187fe2bc33f8423cd535d5045899699995b.tar.gz
Add struct cgit_page to cgit_context
This struct is used when generating http headers, and as such is another small step towards the goal of the whole cleanup series; to invoke each page/view function with a function pointer. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r--cgit.c50
-rw-r--r--cgit.h18
-rw-r--r--shared.c3
-rw-r--r--ui-blob.c4
-rw-r--r--ui-patch.c4
-rw-r--r--ui-repolist.c6
-rw-r--r--ui-shared.c112
-rw-r--r--ui-snapshot.c4
8 files changed, 113 insertions, 88 deletions
diff --git a/cgit.c b/cgit.c
index e6b4526..d0f6905 100644
--- a/cgit.c
+++ b/cgit.c
@@ -7,13 +7,16 @@
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include "cmd.h"
10 11
11static int cgit_prepare_cache(struct cacheitem *item) 12static int cgit_prepare_cache(struct cacheitem *item)
12{ 13{
13 if (!ctx.repo && ctx.qry.repo) { 14 if (!ctx.repo && ctx.qry.repo) {
14 char *title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); 15 ctx.page.title = fmt("%s - %s", ctx.cfg.root_title,
15 cgit_print_docstart(title, item); 16 "Bad request");
16 cgit_print_pageheader(title, 0); 17 cgit_print_http_headers(&ctx);
18 cgit_print_docstart(&ctx);
19 cgit_print_pageheader(&ctx);
17 cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); 20 cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo));
18 cgit_print_docend(); 21 cgit_print_docend();
19 return 0; 22 return 0;
@@ -80,7 +83,7 @@ char *find_default_branch(struct cgit_repo *repo)
80 83
81static void cgit_print_repo_page(struct cacheitem *item) 84static void cgit_print_repo_page(struct cacheitem *item)
82{ 85{
83 char *title, *tmp; 86 char *tmp;
84 int show_search; 87 int show_search;
85 unsigned char sha1[20]; 88 unsigned char sha1[20];
86 int nongit = 0; 89 int nongit = 0;
@@ -88,17 +91,19 @@ static void cgit_print_repo_page(struct cacheitem *item)
88 setenv("GIT_DIR", ctx.repo->path, 1); 91 setenv("GIT_DIR", ctx.repo->path, 1);
89 setup_git_directory_gently(&nongit); 92 setup_git_directory_gently(&nongit);
90 if (nongit) { 93 if (nongit) {
91 title = fmt("%s - %s", ctx.cfg.root_title, "config error"); 94 ctx.page.title = fmt("%s - %s", ctx.cfg.root_title,
95 "config error");
92 tmp = fmt("Not a git repository: '%s'", ctx.repo->path); 96 tmp = fmt("Not a git repository: '%s'", ctx.repo->path);
93 ctx.repo = NULL; 97 ctx.repo = NULL;
94 cgit_print_docstart(title, item); 98 cgit_print_http_headers(&ctx);
95 cgit_print_pageheader(title, 0); 99 cgit_print_docstart(&ctx);
100 cgit_print_pageheader(&ctx);
96 cgit_print_error(tmp); 101 cgit_print_error(tmp);
97 cgit_print_docend(); 102 cgit_print_docend();
98 return; 103 return;
99 } 104 }
100 105
101 title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc); 106 ctx.page.title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc);
102 show_search = 0; 107 show_search = 0;
103 108
104 if (!ctx.qry.head) { 109 if (!ctx.qry.head) {
@@ -107,8 +112,9 @@ static void cgit_print_repo_page(struct cacheitem *item)
107 } 112 }
108 113
109 if (!ctx.qry.head) { 114 if (!ctx.qry.head) {
110 cgit_print_docstart(title, item); 115 cgit_print_http_headers(&ctx);
111 cgit_print_pageheader(title, 0); 116 cgit_print_docstart(&ctx);
117 cgit_print_pageheader(&ctx);
112 cgit_print_error("Repository seems to be empty"); 118 cgit_print_error("Repository seems to be empty");
113 cgit_print_docend(); 119 cgit_print_docend();
114 return; 120 return;
@@ -117,8 +123,9 @@ static void cgit_print_repo_page(struct cacheitem *item)
117 if (get_sha1(ctx.qry.head, sha1)) { 123 if (get_sha1(ctx.qry.head, sha1)) {
118 tmp = xstrdup(ctx.qry.head); 124 tmp = xstrdup(ctx.qry.head);
119 ctx.qry.head = ctx.repo->defbranch; 125 ctx.qry.head = ctx.repo->defbranch;
120 cgit_print_docstart(title, item); 126 cgit_print_http_headers(&ctx);
121 cgit_print_pageheader(title, 0); 127 cgit_print_docstart(&ctx);
128 cgit_print_pageheader(&ctx);
122 cgit_print_error(fmt("Invalid branch: %s", tmp)); 129 cgit_print_error(fmt("Invalid branch: %s", tmp));
123 cgit_print_docend(); 130 cgit_print_docend();
124 return; 131 return;
@@ -143,15 +150,16 @@ static void cgit_print_repo_page(struct cacheitem *item)
143 } 150 }
144 151
145 show_search = (cgit_cmd == CMD_LOG); 152 show_search = (cgit_cmd == CMD_LOG);
146 cgit_print_docstart(title, item); 153 cgit_print_http_headers(&ctx);
154 cgit_print_docstart(&ctx);
147 if (!cgit_cmd) { 155 if (!cgit_cmd) {
148 cgit_print_pageheader("summary", show_search); 156 cgit_print_pageheader(&ctx);
149 cgit_print_summary(); 157 cgit_print_summary();
150 cgit_print_docend(); 158 cgit_print_docend();
151 return; 159 return;
152 } 160 }
153 161
154 cgit_print_pageheader(ctx.qry.page, show_search); 162 cgit_print_pageheader(&ctx);
155 163
156 switch(cgit_cmd) { 164 switch(cgit_cmd) {
157 case CMD_LOG: 165 case CMD_LOG:
@@ -180,12 +188,18 @@ static void cgit_print_repo_page(struct cacheitem *item)
180 cgit_print_docend(); 188 cgit_print_docend();
181} 189}
182 190
191static long ttl_seconds(long ttl)
192{
193 if (ttl<0)
194 return 60 * 60 * 24 * 365;
195 else
196 return ttl * 60;
197}
198
183static void cgit_fill_cache(struct cacheitem *item, int use_cache) 199static void cgit_fill_cache(struct cacheitem *item, int use_cache)
184{ 200{
185 int stdout2; 201 int stdout2;
186 202
187 item->st.st_mtime = time(NULL);
188
189 if (use_cache) { 203 if (use_cache) {
190 stdout2 = chk_positive(dup(STDOUT_FILENO), 204 stdout2 = chk_positive(dup(STDOUT_FILENO),
191 "Preserving STDOUT"); 205 "Preserving STDOUT");
@@ -193,6 +207,8 @@ static void cgit_fill_cache(struct cacheitem *item, int use_cache)
193 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); 207 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)");
194 } 208 }
195 209
210 ctx.page.modified = time(NULL);
211 ctx.page.expires = ctx.page.modified + ttl_seconds(item->ttl);
196 if (ctx.repo) 212 if (ctx.repo)
197 cgit_print_repo_page(item); 213 cgit_print_repo_page(item);
198 else 214 else
diff --git a/cgit.h b/cgit.h
index 5b7ee1c..8ab8e07 100644
--- a/cgit.h
+++ b/cgit.h
@@ -174,10 +174,20 @@ struct cgit_config {
174 int summary_tags; 174 int summary_tags;
175}; 175};
176 176
177struct cgit_page {
178 time_t modified;
179 time_t expires;
180 char *mimetype;
181 char *charset;
182 char *filename;
183 char *title;
184};
185
177struct cgit_context { 186struct cgit_context {
178 struct cgit_query qry; 187 struct cgit_query qry;
179 struct cgit_config cfg; 188 struct cgit_config cfg;
180 struct cgit_repo *repo; 189 struct cgit_repo *repo;
190 struct cgit_page page;
181}; 191};
182 192
183extern const char *cgit_version; 193extern const char *cgit_version;
@@ -260,12 +270,10 @@ extern void cgit_object_link(struct object *obj);
260extern void cgit_print_error(char *msg); 270extern void cgit_print_error(char *msg);
261extern void cgit_print_date(time_t secs, char *format); 271extern void cgit_print_date(time_t secs, char *format);
262extern void cgit_print_age(time_t t, time_t max_relative, char *format); 272extern void cgit_print_age(time_t t, time_t max_relative, char *format);
263extern void cgit_print_docstart(char *title, struct cacheitem *item); 273extern void cgit_print_http_headers(struct cgit_context *ctx);
274extern void cgit_print_docstart(struct cgit_context *ctx);
264extern void cgit_print_docend(); 275extern void cgit_print_docend();
265extern void cgit_print_pageheader(char *title, int show_search); 276extern void cgit_print_pageheader(struct cgit_context *ctx);
266extern void cgit_print_snapshot_start(const char *mimetype,
267 const char *filename,
268 struct cacheitem *item);
269extern void cgit_print_filemode(unsigned short mode); 277extern void cgit_print_filemode(unsigned short mode);
270extern void cgit_print_branches(int maxcount); 278extern void cgit_print_branches(int maxcount);
271extern void cgit_print_tags(int maxcount); 279extern void cgit_print_tags(int maxcount);
diff --git a/shared.c b/shared.c
index 76e10d0..539d533 100644
--- a/shared.c
+++ b/shared.c
@@ -35,6 +35,9 @@ void cgit_prepare_context(struct cgit_context *ctx)
35 ctx->cfg.robots = "index, nofollow"; 35 ctx->cfg.robots = "index, nofollow";
36 ctx->cfg.root_title = "Git repository browser"; 36 ctx->cfg.root_title = "Git repository browser";
37 ctx->cfg.script_name = CGIT_SCRIPT_NAME; 37 ctx->cfg.script_name = CGIT_SCRIPT_NAME;
38 ctx->page.mimetype = "text/html";
39 ctx->page.charset = PAGE_ENCODING;
40 ctx->page.filename = NULL;
38} 41}
39 42
40int cgit_get_cmd_index(const char *cmd) 43int cgit_get_cmd_index(const char *cmd)
diff --git a/ui-blob.c b/ui-blob.c
index be4fb88..bd44574 100644
--- a/ui-blob.c
+++ b/ui-blob.c
@@ -35,6 +35,8 @@ void cgit_print_blob(struct cacheitem *item, const char *hex, char *path)
35 } 35 }
36 36
37 buf[size] = '\0'; 37 buf[size] = '\0';
38 cgit_print_snapshot_start("text/plain", path, item); 38 ctx.page.mimetype = "text/plain";
39 ctx.page.filename = path;
40 cgit_print_http_headers(&ctx);
39 write(htmlfd, buf, size); 41 write(htmlfd, buf, size);
40} 42}
diff --git a/ui-patch.c b/ui-patch.c
index d93426b..a77f3f6 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -92,7 +92,9 @@ void cgit_print_patch(char *hex, struct cacheitem *item)
92 hashcpy(old_sha1, commit->parents->item->object.sha1); 92 hashcpy(old_sha1, commit->parents->item->object.sha1);
93 93
94 patchname = fmt("%s.patch", sha1_to_hex(sha1)); 94 patchname = fmt("%s.patch", sha1_to_hex(sha1));
95 cgit_print_snapshot_start("text/plain", patchname, item); 95 ctx.page.mimetype = "text/plain";
96 ctx.page.filename = patchname;
97 cgit_print_http_headers(&ctx);
96 htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); 98 htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1));
97 htmlf("From: %s%s\n", info->author, info->author_email); 99 htmlf("From: %s%s\n", info->author, info->author_email);
98 html("Date: "); 100 html("Date: ");
diff --git a/ui-repolist.c b/ui-repolist.c
index cd4e41d..e663585 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -51,8 +51,10 @@ void cgit_print_repolist(struct cacheitem *item)
51 if (ctx.cfg.enable_index_links) 51 if (ctx.cfg.enable_index_links)
52 columns++; 52 columns++;
53 53
54 cgit_print_docstart(ctx.cfg.root_title, item); 54 ctx.page.title = ctx.cfg.root_title;
55 cgit_print_pageheader(ctx.cfg.root_title, 0); 55 cgit_print_http_headers(&ctx);
56 cgit_print_docstart(&ctx);
57 cgit_print_pageheader(&ctx);
56 58
57 html("<table summary='repository list' class='list nowrap'>"); 59 html("<table summary='repository list' class='list nowrap'>");
58 if (ctx.cfg.index_header) { 60 if (ctx.cfg.index_header) {
diff --git a/ui-shared.c b/ui-shared.c
index 2eff79d..2596023 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -26,14 +26,6 @@ static char *http_date(time_t t)
26 tm->tm_hour, tm->tm_min, tm->tm_sec); 26 tm->tm_hour, tm->tm_min, tm->tm_sec);
27} 27}
28 28
29static long ttl_seconds(long ttl)
30{
31 if (ttl<0)
32 return 60 * 60 * 24 * 365;
33 else
34 return ttl * 60;
35}
36
37void cgit_print_error(char *msg) 29void cgit_print_error(char *msg)
38{ 30{
39 html("<div class='error'>"); 31 html("<div class='error'>");
@@ -361,24 +353,34 @@ void cgit_print_age(time_t t, time_t max_relative, char *format)
361 secs * 1.0 / TM_YEAR); 353 secs * 1.0 / TM_YEAR);
362} 354}
363 355
364void cgit_print_docstart(char *title, struct cacheitem *item) 356void cgit_print_http_headers(struct cgit_context *ctx)
365{ 357{
366 html("Content-Type: text/html; charset=" PAGE_ENCODING "\n"); 358 if (ctx->page.mimetype && ctx->page.charset)
367 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 359 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
368 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 360 ctx->page.charset);
369 ttl_seconds(item->ttl))); 361 else if (ctx->page.mimetype)
362 htmlf("Content-Type: %s\n", ctx->page.mimetype);
363 if (ctx->page.filename)
364 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
365 ctx->page.filename);
366 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
367 htmlf("Expires: %s\n", http_date(ctx->page.expires));
370 html("\n"); 368 html("\n");
369}
370
371void cgit_print_docstart(struct cgit_context *ctx)
372{
371 html(cgit_doctype); 373 html(cgit_doctype);
372 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 374 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
373 html("<head>\n"); 375 html("<head>\n");
374 html("<title>"); 376 html("<title>");
375 html_txt(title); 377 html_txt(ctx->page.title);
376 html("</title>\n"); 378 html("</title>\n");
377 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 379 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
378 if (ctx.cfg.robots && *ctx.cfg.robots) 380 if (ctx->cfg.robots && *ctx->cfg.robots)
379 htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots); 381 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots);
380 html("<link rel='stylesheet' type='text/css' href='"); 382 html("<link rel='stylesheet' type='text/css' href='");
381 html_attr(ctx.cfg.css); 383 html_attr(ctx->cfg.css);
382 html("'/>\n"); 384 html("'/>\n");
383 html("</head>\n"); 385 html("</head>\n");
384 html("<body>\n"); 386 html("<body>\n");
@@ -463,7 +465,7 @@ void add_hidden_formfields(int incl_head, int incl_search, char *page)
463 } 465 }
464} 466}
465 467
466void cgit_print_pageheader(char *title, int show_search) 468void cgit_print_pageheader(struct cgit_context *ctx)
467{ 469{
468 static const char *default_info = "This is cgit, a fast webinterface for git repositories"; 470 static const char *default_info = "This is cgit, a fast webinterface for git repositories";
469 int header = 0; 471 int header = 0;
@@ -475,40 +477,40 @@ void cgit_print_pageheader(char *title, int show_search)
475 html("<tr><td class='sidebar'>\n<a href='"); 477 html("<tr><td class='sidebar'>\n<a href='");
476 html_attr(cgit_rooturl()); 478 html_attr(cgit_rooturl());
477 htmlf("'><img src='%s' alt='cgit'/></a>\n", 479 htmlf("'><img src='%s' alt='cgit'/></a>\n",
478 ctx.cfg.logo); 480 ctx->cfg.logo);
479 html("</td></tr>\n<tr><td class='sidebar'>\n"); 481 html("</td></tr>\n<tr><td class='sidebar'>\n");
480 if (ctx.repo) { 482 if (ctx->repo) {
481 html("<h1 class='first'>"); 483 html("<h1 class='first'>");
482 html_txt(strrpart(ctx.repo->name, 20)); 484 html_txt(strrpart(ctx->repo->name, 20));
483 html("</h1>\n"); 485 html("</h1>\n");
484 html_txt(ctx.repo->desc); 486 html_txt(ctx->repo->desc);
485 if (ctx.repo->owner) { 487 if (ctx->repo->owner) {
486 html("<h1>owner</h1>\n"); 488 html("<h1>owner</h1>\n");
487 html_txt(ctx.repo->owner); 489 html_txt(ctx->repo->owner);
488 } 490 }
489 html("<h1>navigate</h1>\n"); 491 html("<h1>navigate</h1>\n");
490 reporevlink(NULL, "summary", NULL, "menu", ctx.qry.head, 492 reporevlink(NULL, "summary", NULL, "menu", ctx->qry.head,
491 NULL, NULL); 493 NULL, NULL);
492 cgit_log_link("log", NULL, "menu", ctx.qry.head, NULL, NULL, 494 cgit_log_link("log", NULL, "menu", ctx->qry.head, NULL, NULL,
493 0, NULL, NULL); 495 0, NULL, NULL);
494 cgit_tree_link("tree", NULL, "menu", ctx.qry.head, 496 cgit_tree_link("tree", NULL, "menu", ctx->qry.head,
495 ctx.qry.sha1, NULL); 497 ctx->qry.sha1, NULL);
496 cgit_commit_link("commit", NULL, "menu", ctx.qry.head, 498 cgit_commit_link("commit", NULL, "menu", ctx->qry.head,
497 ctx.qry.sha1); 499 ctx->qry.sha1);
498 cgit_diff_link("diff", NULL, "menu", ctx.qry.head, 500 cgit_diff_link("diff", NULL, "menu", ctx->qry.head,
499 ctx.qry.sha1, ctx.qry.sha2, NULL); 501 ctx->qry.sha1, ctx->qry.sha2, NULL);
500 cgit_patch_link("patch", NULL, "menu", ctx.qry.head, 502 cgit_patch_link("patch", NULL, "menu", ctx->qry.head,
501 ctx.qry.sha1); 503 ctx->qry.sha1);
502 504
503 for_each_ref(print_archive_ref, &header); 505 for_each_ref(print_archive_ref, &header);
504 506
505 if (ctx.repo->clone_url || ctx.cfg.clone_prefix) { 507 if (ctx->repo->clone_url || ctx->cfg.clone_prefix) {
506 html("<h1>clone</h1>\n"); 508 html("<h1>clone</h1>\n");
507 if (ctx.repo->clone_url) 509 if (ctx->repo->clone_url)
508 url = ctx.repo->clone_url; 510 url = ctx->repo->clone_url;
509 else 511 else
510 url = fmt("%s%s", ctx.cfg.clone_prefix, 512 url = fmt("%s%s", ctx->cfg.clone_prefix,
511 ctx.repo->url); 513 ctx->repo->url);
512 html("<a class='menu' href='"); 514 html("<a class='menu' href='");
513 html_attr(url); 515 html_attr(url);
514 html("' title='"); 516 html("' title='");
@@ -520,10 +522,10 @@ void cgit_print_pageheader(char *title, int show_search)
520 522
521 html("<h1>branch</h1>\n"); 523 html("<h1>branch</h1>\n");
522 html("<form method='get' action=''>\n"); 524 html("<form method='get' action=''>\n");
523 add_hidden_formfields(0, 1, ctx.qry.page); 525 add_hidden_formfields(0, 1, ctx->qry.page);
524// html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); 526// html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>");
525 html("<select name='h' onchange='this.form.submit();'>\n"); 527 html("<select name='h' onchange='this.form.submit();'>\n");
526 for_each_branch_ref(print_branch_option, ctx.qry.head); 528 for_each_branch_ref(print_branch_option, ctx->qry.head);
527 html("</select>\n"); 529 html("</select>\n");
528// html("</td><td>"); 530// html("</td><td>");
529 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); 531 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n");
@@ -532,22 +534,22 @@ void cgit_print_pageheader(char *title, int show_search)
532 534
533 html("<h1>search</h1>\n"); 535 html("<h1>search</h1>\n");
534 html("<form method='get' action='"); 536 html("<form method='get' action='");
535 if (ctx.cfg.virtual_root) 537 if (ctx->cfg.virtual_root)
536 html_attr(cgit_fileurl(ctx.qry.repo, "log", 538 html_attr(cgit_fileurl(ctx->qry.repo, "log",
537 ctx.qry.path, NULL)); 539 ctx->qry.path, NULL));
538 html("'>\n"); 540 html("'>\n");
539 add_hidden_formfields(1, 0, "log"); 541 add_hidden_formfields(1, 0, "log");
540 html("<select name='qt'>\n"); 542 html("<select name='qt'>\n");
541 html_option("grep", "log msg", ctx.qry.grep); 543 html_option("grep", "log msg", ctx->qry.grep);
542 html_option("author", "author", ctx.qry.grep); 544 html_option("author", "author", ctx->qry.grep);
543 html_option("committer", "committer", ctx.qry.grep); 545 html_option("committer", "committer", ctx->qry.grep);
544 html("</select>\n"); 546 html("</select>\n");
545 html("<input class='txt' type='text' name='q' value='"); 547 html("<input class='txt' type='text' name='q' value='");
546 html_attr(ctx.qry.search); 548 html_attr(ctx->qry.search);
547 html("'/>\n"); 549 html("'/>\n");
548 html("</form>\n"); 550 html("</form>\n");
549 } else { 551 } else {
550 if (!ctx.cfg.index_info || html_include(ctx.cfg.index_info)) 552 if (!ctx->cfg.index_info || html_include(ctx->cfg.index_info))
551 html(default_info); 553 html(default_info);
552 } 554 }
553 555
@@ -556,18 +558,6 @@ void cgit_print_pageheader(char *title, int show_search)
556 html("<td id='content'>\n"); 558 html("<td id='content'>\n");
557} 559}
558 560
559
560void cgit_print_snapshot_start(const char *mimetype, const char *filename,
561 struct cacheitem *item)
562{
563 htmlf("Content-Type: %s\n", mimetype);
564 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename);
565 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
566 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
567 ttl_seconds(item->ttl)));
568 html("\n");
569}
570
571void cgit_print_filemode(unsigned short mode) 561void cgit_print_filemode(unsigned short mode)
572{ 562{
573 if (S_ISDIR(mode)) 563 if (S_ISDIR(mode))
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 67dbbdd..4449803 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -101,7 +101,9 @@ void cgit_print_snapshot(struct cacheitem *item, const char *head,
101 args.base = fmt("%s/", prefix); 101 args.base = fmt("%s/", prefix);
102 args.tree = commit->tree; 102 args.tree = commit->tree;
103 args.time = commit->date; 103 args.time = commit->date;
104 cgit_print_snapshot_start(sat->mimetype, filename, item); 104 ctx.page.mimetype = xstrdup(sat->mimetype);
105 ctx.page.filename = xstrdup(filename);
106 cgit_print_http_headers(&ctx);
105 (*sat->write_func)(&args); 107 (*sat->write_func)(&args);
106 return; 108 return;
107 } 109 }