-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 | |||
@@ -33,8 +33,19 @@ void cgit_print_error(char *msg) | |||
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 | ||
@@ -455,11 +466,15 @@ void cgit_print_age(time_t t, time_t max_relative, char *format) | |||
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) |
@@ -470,9 +485,13 @@ void cgit_print_http_headers(struct cgit_context *ctx) | |||
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 | { |
@@ -497,14 +516,17 @@ void cgit_print_docstart(struct cgit_context *ctx) | |||
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); |