author | Lars Hjemli <hjemli@gmail.com> | 2009-02-19 22:24:15 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-02-19 22:24:15 (UTC) |
commit | 3ff58ddd51bcbcbc9b7649bad1a39aa98af4b49f (patch) (unidiff) | |
tree | 4ff1b54dfb2fc025771f39528165e9e46d93a0e0 /ui-shared.c | |
parent | 488a214a81a25c6397c56822ed1713f51dddc520 (diff) | |
download | cgit-3ff58ddd51bcbcbc9b7649bad1a39aa98af4b49f.zip cgit-3ff58ddd51bcbcbc9b7649bad1a39aa98af4b49f.tar.gz cgit-3ff58ddd51bcbcbc9b7649bad1a39aa98af4b49f.tar.bz2 |
Add support for HEAD requests
This is a quick 'n dirty hack which makes cgit honor HEAD requests.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-shared.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c index 86a7d29..0dafc83 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -395,143 +395,147 @@ void cgit_object_link(struct object *obj) | |||
395 | name = fmt("%s %s...", typename(obj->type), shortrev); | 395 | name = fmt("%s %s...", typename(obj->type), shortrev); |
396 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); | 396 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); |
397 | } | 397 | } |
398 | 398 | ||
399 | void cgit_print_date(time_t secs, char *format, int local_time) | 399 | void cgit_print_date(time_t secs, char *format, int local_time) |
400 | { | 400 | { |
401 | char buf[64]; | 401 | char buf[64]; |
402 | struct tm *time; | 402 | struct tm *time; |
403 | 403 | ||
404 | if (!secs) | 404 | if (!secs) |
405 | return; | 405 | return; |
406 | if(local_time) | 406 | if(local_time) |
407 | time = localtime(&secs); | 407 | time = localtime(&secs); |
408 | else | 408 | else |
409 | time = gmtime(&secs); | 409 | time = gmtime(&secs); |
410 | strftime(buf, sizeof(buf)-1, format, time); | 410 | strftime(buf, sizeof(buf)-1, format, time); |
411 | html_txt(buf); | 411 | html_txt(buf); |
412 | } | 412 | } |
413 | 413 | ||
414 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 414 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
415 | { | 415 | { |
416 | time_t now, secs; | 416 | time_t now, secs; |
417 | 417 | ||
418 | if (!t) | 418 | if (!t) |
419 | return; | 419 | return; |
420 | time(&now); | 420 | time(&now); |
421 | secs = now - t; | 421 | secs = now - t; |
422 | 422 | ||
423 | if (secs > max_relative && max_relative >= 0) { | 423 | if (secs > max_relative && max_relative >= 0) { |
424 | cgit_print_date(t, format, ctx.cfg.local_time); | 424 | cgit_print_date(t, format, ctx.cfg.local_time); |
425 | return; | 425 | return; |
426 | } | 426 | } |
427 | 427 | ||
428 | if (secs < TM_HOUR * 2) { | 428 | if (secs < TM_HOUR * 2) { |
429 | htmlf("<span class='age-mins'>%.0f min.</span>", | 429 | htmlf("<span class='age-mins'>%.0f min.</span>", |
430 | secs * 1.0 / TM_MIN); | 430 | secs * 1.0 / TM_MIN); |
431 | return; | 431 | return; |
432 | } | 432 | } |
433 | if (secs < TM_DAY * 2) { | 433 | if (secs < TM_DAY * 2) { |
434 | htmlf("<span class='age-hours'>%.0f hours</span>", | 434 | htmlf("<span class='age-hours'>%.0f hours</span>", |
435 | secs * 1.0 / TM_HOUR); | 435 | secs * 1.0 / TM_HOUR); |
436 | return; | 436 | return; |
437 | } | 437 | } |
438 | if (secs < TM_WEEK * 2) { | 438 | if (secs < TM_WEEK * 2) { |
439 | htmlf("<span class='age-days'>%.0f days</span>", | 439 | htmlf("<span class='age-days'>%.0f days</span>", |
440 | secs * 1.0 / TM_DAY); | 440 | secs * 1.0 / TM_DAY); |
441 | return; | 441 | return; |
442 | } | 442 | } |
443 | if (secs < TM_MONTH * 2) { | 443 | if (secs < TM_MONTH * 2) { |
444 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 444 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
445 | secs * 1.0 / TM_WEEK); | 445 | secs * 1.0 / TM_WEEK); |
446 | return; | 446 | return; |
447 | } | 447 | } |
448 | if (secs < TM_YEAR * 2) { | 448 | if (secs < TM_YEAR * 2) { |
449 | htmlf("<span class='age-months'>%.0f months</span>", | 449 | htmlf("<span class='age-months'>%.0f months</span>", |
450 | secs * 1.0 / TM_MONTH); | 450 | secs * 1.0 / TM_MONTH); |
451 | return; | 451 | return; |
452 | } | 452 | } |
453 | htmlf("<span class='age-years'>%.0f years</span>", | 453 | htmlf("<span class='age-years'>%.0f years</span>", |
454 | secs * 1.0 / TM_YEAR); | 454 | secs * 1.0 / TM_YEAR); |
455 | } | 455 | } |
456 | 456 | ||
457 | void cgit_print_http_headers(struct cgit_context *ctx) | 457 | void cgit_print_http_headers(struct cgit_context *ctx) |
458 | { | 458 | { |
459 | const char *method = getenv("REQUEST_METHOD"); | ||
460 | |||
459 | if (ctx->page.mimetype && ctx->page.charset) | 461 | if (ctx->page.mimetype && ctx->page.charset) |
460 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, | 462 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, |
461 | ctx->page.charset); | 463 | ctx->page.charset); |
462 | else if (ctx->page.mimetype) | 464 | else if (ctx->page.mimetype) |
463 | htmlf("Content-Type: %s\n", ctx->page.mimetype); | 465 | htmlf("Content-Type: %s\n", ctx->page.mimetype); |
464 | if (ctx->page.size) | 466 | if (ctx->page.size) |
465 | htmlf("Content-Length: %ld\n", ctx->page.size); | 467 | htmlf("Content-Length: %ld\n", ctx->page.size); |
466 | if (ctx->page.filename) | 468 | if (ctx->page.filename) |
467 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", | 469 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", |
468 | ctx->page.filename); | 470 | ctx->page.filename); |
469 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); | 471 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); |
470 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); | 472 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); |
471 | if (ctx->page.etag) | 473 | if (ctx->page.etag) |
472 | htmlf("ETag: \"%s\"\n", ctx->page.etag); | 474 | htmlf("ETag: \"%s\"\n", ctx->page.etag); |
473 | html("\n"); | 475 | html("\n"); |
476 | if (method && !strcmp(method, "HEAD")) | ||
477 | exit(0); | ||
474 | } | 478 | } |
475 | 479 | ||
476 | void cgit_print_docstart(struct cgit_context *ctx) | 480 | void cgit_print_docstart(struct cgit_context *ctx) |
477 | { | 481 | { |
478 | char *host = cgit_hosturl(); | 482 | char *host = cgit_hosturl(); |
479 | html(cgit_doctype); | 483 | html(cgit_doctype); |
480 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 484 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
481 | html("<head>\n"); | 485 | html("<head>\n"); |
482 | html("<title>"); | 486 | html("<title>"); |
483 | html_txt(ctx->page.title); | 487 | html_txt(ctx->page.title); |
484 | html("</title>\n"); | 488 | html("</title>\n"); |
485 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 489 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
486 | if (ctx->cfg.robots && *ctx->cfg.robots) | 490 | if (ctx->cfg.robots && *ctx->cfg.robots) |
487 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); | 491 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
488 | html("<link rel='stylesheet' type='text/css' href='"); | 492 | html("<link rel='stylesheet' type='text/css' href='"); |
489 | html_attr(ctx->cfg.css); | 493 | html_attr(ctx->cfg.css); |
490 | html("'/>\n"); | 494 | html("'/>\n"); |
491 | if (ctx->cfg.favicon) { | 495 | if (ctx->cfg.favicon) { |
492 | html("<link rel='shortcut icon' href='"); | 496 | html("<link rel='shortcut icon' href='"); |
493 | html_attr(ctx->cfg.favicon); | 497 | html_attr(ctx->cfg.favicon); |
494 | html("'/>\n"); | 498 | html("'/>\n"); |
495 | } | 499 | } |
496 | if (host && ctx->repo) { | 500 | if (host && ctx->repo) { |
497 | html("<link rel='alternate' title='Atom feed' href='http://"); | 501 | html("<link rel='alternate' title='Atom feed' href='http://"); |
498 | html_attr(cgit_hosturl()); | 502 | html_attr(cgit_hosturl()); |
499 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, | 503 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, |
500 | fmt("h=%s", ctx->qry.head))); | 504 | fmt("h=%s", ctx->qry.head))); |
501 | html("' type='application/atom+xml'/>"); | 505 | html("' type='application/atom+xml'/>"); |
502 | } | 506 | } |
503 | html("</head>\n"); | 507 | html("</head>\n"); |
504 | html("<body>\n"); | 508 | html("<body>\n"); |
505 | if (ctx->cfg.header) | 509 | if (ctx->cfg.header) |
506 | html_include(ctx->cfg.header); | 510 | html_include(ctx->cfg.header); |
507 | } | 511 | } |
508 | 512 | ||
509 | void cgit_print_docend() | 513 | void cgit_print_docend() |
510 | { | 514 | { |
511 | html("</div>"); | 515 | html("</div>"); |
512 | if (ctx.cfg.footer) | 516 | if (ctx.cfg.footer) |
513 | html_include(ctx.cfg.footer); | 517 | html_include(ctx.cfg.footer); |
514 | else { | 518 | else { |
515 | htmlf("<div class='footer'>generated by cgit %s at ", | 519 | htmlf("<div class='footer'>generated by cgit %s at ", |
516 | cgit_version); | 520 | cgit_version); |
517 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); | 521 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); |
518 | html("</div>\n"); | 522 | html("</div>\n"); |
519 | } | 523 | } |
520 | html("</body>\n</html>\n"); | 524 | html("</body>\n</html>\n"); |
521 | } | 525 | } |
522 | 526 | ||
523 | int print_branch_option(const char *refname, const unsigned char *sha1, | 527 | int print_branch_option(const char *refname, const unsigned char *sha1, |
524 | int flags, void *cb_data) | 528 | int flags, void *cb_data) |
525 | { | 529 | { |
526 | char *name = (char *)refname; | 530 | char *name = (char *)refname; |
527 | html_option(name, name, ctx.qry.head); | 531 | html_option(name, name, ctx.qry.head); |
528 | return 0; | 532 | return 0; |
529 | } | 533 | } |
530 | 534 | ||
531 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 535 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
532 | int flags, void *cb_data) | 536 | int flags, void *cb_data) |
533 | { | 537 | { |
534 | struct tag *tag; | 538 | struct tag *tag; |
535 | struct taginfo *info; | 539 | struct taginfo *info; |
536 | struct object *obj; | 540 | struct object *obj; |
537 | char buf[256], *url; | 541 | char buf[256], *url; |