mirror of
https://git.zx2c4.com/cgit
synced 2024-11-25 18:08:41 +00:00
Merge branch 'plain-etag'
Conflicts: ui-shared.c
This commit is contained in:
commit
681fdc4547
4
cgit.c
4
cgit.c
@ -206,6 +206,7 @@ static void prepare_context(struct cgit_context *ctx)
|
|||||||
ctx->page.size = 0;
|
ctx->page.size = 0;
|
||||||
ctx->page.modified = time(NULL);
|
ctx->page.modified = time(NULL);
|
||||||
ctx->page.expires = ctx->page.modified;
|
ctx->page.expires = ctx->page.modified;
|
||||||
|
ctx->page.etag = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct refmatch {
|
struct refmatch {
|
||||||
@ -431,6 +432,7 @@ static int calc_ttl()
|
|||||||
int main(int argc, const char **argv)
|
int main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
const char *cgit_config_env = getenv("CGIT_CONFIG");
|
const char *cgit_config_env = getenv("CGIT_CONFIG");
|
||||||
|
const char *method = getenv("REQUEST_METHOD");
|
||||||
const char *path;
|
const char *path;
|
||||||
char *qry;
|
char *qry;
|
||||||
int err, ttl;
|
int err, ttl;
|
||||||
@ -477,6 +479,8 @@ int main(int argc, const char **argv)
|
|||||||
|
|
||||||
ttl = calc_ttl();
|
ttl = calc_ttl();
|
||||||
ctx.page.expires += ttl*60;
|
ctx.page.expires += ttl*60;
|
||||||
|
if (method && !strcmp(method, "HEAD"))
|
||||||
|
ctx.cfg.nocache = 1;
|
||||||
if (ctx.cfg.nocache)
|
if (ctx.cfg.nocache)
|
||||||
ctx.cfg.cache_size = 0;
|
ctx.cfg.cache_size = 0;
|
||||||
err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
|
err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
|
||||||
|
1
cgit.h
1
cgit.h
@ -180,6 +180,7 @@ struct cgit_page {
|
|||||||
char *mimetype;
|
char *mimetype;
|
||||||
char *charset;
|
char *charset;
|
||||||
char *filename;
|
char *filename;
|
||||||
|
char *etag;
|
||||||
char *title;
|
char *title;
|
||||||
int status;
|
int status;
|
||||||
char *statusmsg;
|
char *statusmsg;
|
||||||
|
@ -37,6 +37,7 @@ static void print_object(const unsigned char *sha1, const char *path)
|
|||||||
ctx.page.mimetype = "text/plain";
|
ctx.page.mimetype = "text/plain";
|
||||||
ctx.page.filename = fmt("%s", path);
|
ctx.page.filename = fmt("%s", path);
|
||||||
ctx.page.size = size;
|
ctx.page.size = size;
|
||||||
|
ctx.page.etag = sha1_to_hex(sha1);
|
||||||
cgit_print_http_headers(&ctx);
|
cgit_print_http_headers(&ctx);
|
||||||
html_raw(buf, size);
|
html_raw(buf, size);
|
||||||
match = 1;
|
match = 1;
|
||||||
|
@ -467,6 +467,8 @@ void cgit_print_age(time_t t, time_t max_relative, char *format)
|
|||||||
|
|
||||||
void cgit_print_http_headers(struct cgit_context *ctx)
|
void cgit_print_http_headers(struct cgit_context *ctx)
|
||||||
{
|
{
|
||||||
|
const char *method = getenv("REQUEST_METHOD");
|
||||||
|
|
||||||
if (ctx->page.status)
|
if (ctx->page.status)
|
||||||
htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg);
|
htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg);
|
||||||
if (ctx->page.mimetype && ctx->page.charset)
|
if (ctx->page.mimetype && ctx->page.charset)
|
||||||
@ -481,7 +483,11 @@ void cgit_print_http_headers(struct cgit_context *ctx)
|
|||||||
ctx->page.filename);
|
ctx->page.filename);
|
||||||
htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
|
htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
|
||||||
htmlf("Expires: %s\n", http_date(ctx->page.expires));
|
htmlf("Expires: %s\n", http_date(ctx->page.expires));
|
||||||
|
if (ctx->page.etag)
|
||||||
|
htmlf("ETag: \"%s\"\n", ctx->page.etag);
|
||||||
html("\n");
|
html("\n");
|
||||||
|
if (method && !strcmp(method, "HEAD"))
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cgit_print_docstart(struct cgit_context *ctx)
|
void cgit_print_docstart(struct cgit_context *ctx)
|
||||||
|
Loading…
Reference in New Issue
Block a user