-rw-r--r-- | ui-shared.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/ui-shared.c b/ui-shared.c index 5e03a7a..015c52b 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -29,16 +29,27 @@ static char *http_date(time_t t) | |||
29 | 29 | ||
30 | void cgit_print_error(char *msg) | 30 | void cgit_print_error(char *msg) |
31 | { | 31 | { |
32 | html("<div class='error'>"); | 32 | html("<div class='error'>"); |
33 | html_txt(msg); | 33 | html_txt(msg); |
34 | html("</div>\n"); | 34 | html("</div>\n"); |
35 | } | 35 | } |
36 | 36 | ||
37 | char *cgit_httpscheme() | ||
38 | { | ||
39 | char *https; | ||
40 | |||
41 | https = getenv("HTTPS"); | ||
42 | if (https != NULL && strcmp(https, "on") == 0) | ||
43 | return "https://"; | ||
44 | else | ||
45 | return "http://"; | ||
46 | } | ||
47 | |||
37 | char *cgit_hosturl() | 48 | char *cgit_hosturl() |
38 | { | 49 | { |
39 | char *host, *port; | 50 | char *host, *port; |
40 | 51 | ||
41 | host = getenv("HTTP_HOST"); | 52 | host = getenv("HTTP_HOST"); |
42 | if (host) { | 53 | if (host) { |
43 | host = xstrdup(host); | 54 | host = xstrdup(host); |
44 | } else { | 55 | } else { |
@@ -451,32 +462,40 @@ void cgit_print_age(time_t t, time_t max_relative, char *format) | |||
451 | return; | 462 | return; |
452 | } | 463 | } |
453 | htmlf("<span class='age-years'>%.0f years</span>", | 464 | htmlf("<span class='age-years'>%.0f years</span>", |
454 | secs * 1.0 / TM_YEAR); | 465 | secs * 1.0 / TM_YEAR); |
455 | } | 466 | } |
456 | 467 | ||
457 | void cgit_print_http_headers(struct cgit_context *ctx) | 468 | void cgit_print_http_headers(struct cgit_context *ctx) |
458 | { | 469 | { |
470 | const char *method = getenv("REQUEST_METHOD"); | ||
471 | |||
459 | if (ctx->cfg.embedded) | 472 | if (ctx->cfg.embedded) |
460 | return; | 473 | return; |
461 | 474 | ||
475 | if (ctx->page.status) | ||
476 | htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); | ||
462 | if (ctx->page.mimetype && ctx->page.charset) | 477 | if (ctx->page.mimetype && ctx->page.charset) |
463 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, | 478 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, |
464 | ctx->page.charset); | 479 | ctx->page.charset); |
465 | else if (ctx->page.mimetype) | 480 | else if (ctx->page.mimetype) |
466 | htmlf("Content-Type: %s\n", ctx->page.mimetype); | 481 | htmlf("Content-Type: %s\n", ctx->page.mimetype); |
467 | if (ctx->page.size) | 482 | if (ctx->page.size) |
468 | htmlf("Content-Length: %ld\n", ctx->page.size); | 483 | htmlf("Content-Length: %ld\n", ctx->page.size); |
469 | if (ctx->page.filename) | 484 | if (ctx->page.filename) |
470 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", | 485 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", |
471 | ctx->page.filename); | 486 | ctx->page.filename); |
472 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); | 487 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); |
473 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); | 488 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); |
489 | if (ctx->page.etag) | ||
490 | htmlf("ETag: \"%s\"\n", ctx->page.etag); | ||
474 | html("\n"); | 491 | html("\n"); |
492 | if (method && !strcmp(method, "HEAD")) | ||
493 | exit(0); | ||
475 | } | 494 | } |
476 | 495 | ||
477 | void cgit_print_docstart(struct cgit_context *ctx) | 496 | void cgit_print_docstart(struct cgit_context *ctx) |
478 | { | 497 | { |
479 | if (ctx->cfg.embedded) | 498 | if (ctx->cfg.embedded) |
480 | return; | 499 | return; |
481 | 500 | ||
482 | char *host = cgit_hosturl(); | 501 | char *host = cgit_hosturl(); |
@@ -493,22 +512,25 @@ void cgit_print_docstart(struct cgit_context *ctx) | |||
493 | html_attr(ctx->cfg.css); | 512 | html_attr(ctx->cfg.css); |
494 | html("'/>\n"); | 513 | html("'/>\n"); |
495 | if (ctx->cfg.favicon) { | 514 | if (ctx->cfg.favicon) { |
496 | html("<link rel='shortcut icon' href='"); | 515 | html("<link rel='shortcut icon' href='"); |
497 | html_attr(ctx->cfg.favicon); | 516 | html_attr(ctx->cfg.favicon); |
498 | html("'/>\n"); | 517 | html("'/>\n"); |
499 | } | 518 | } |
500 | if (host && ctx->repo) { | 519 | if (host && ctx->repo) { |
501 | html("<link rel='alternate' title='Atom feed' href='http://"); | 520 | html("<link rel='alternate' title='Atom feed' href='"); |
521 | html(cgit_httpscheme()); | ||
502 | html_attr(cgit_hosturl()); | 522 | html_attr(cgit_hosturl()); |
503 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, | 523 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, |
504 | fmt("h=%s", ctx->qry.head))); | 524 | fmt("h=%s", ctx->qry.head))); |
505 | html("' type='application/atom+xml'/>"); | 525 | html("' type='application/atom+xml'/>\n"); |
506 | } | 526 | } |
527 | if (ctx->cfg.head_include) | ||
528 | html_include(ctx->cfg.head_include); | ||
507 | html("</head>\n"); | 529 | html("</head>\n"); |
508 | html("<body>\n"); | 530 | html("<body>\n"); |
509 | if (ctx->cfg.header) | 531 | if (ctx->cfg.header) |
510 | html_include(ctx->cfg.header); | 532 | html_include(ctx->cfg.header); |
511 | } | 533 | } |
512 | 534 | ||
513 | void cgit_print_docend() | 535 | void cgit_print_docend() |
514 | { | 536 | { |