[PATCH 2 of 2] SSI: implemented "flastmod" SSI command
Matwey V. Kornilov
matwey.kornilov at gmail.com
Mon May 1 10:09:57 UTC 2017
# HG changeset patch
# User Matwey V. Kornilov <matwey.kornilov at gmail.com>
# Date 1493632942 -10800
# Mon May 01 13:02:22 2017 +0300
# Branch fsize
# Node ID 585e9fd5aecdc3e7ea7c484989f837b0cfde627d
# Parent 0d6c509169a32624cce431f2469b10b4f961510e
SSI: implemented "flastmod" SSI command.
diff -r 0d6c509169a3 -r 585e9fd5aecd src/http/modules/ngx_http_ssi_filter_module.c
--- a/src/http/modules/ngx_http_ssi_filter_module.c Sun Apr 23 11:38:23 2017 +0300
+++ b/src/http/modules/ngx_http_ssi_filter_module.c Mon May 01 13:02:22 2017 +0300
@@ -93,6 +93,8 @@
ngx_http_ssi_ctx_t *ctx, ngx_str_t **params);
static ngx_int_t ngx_http_ssi_fsize_output(ngx_http_request_t *r, void *data,
ngx_int_t rc);
+static ngx_int_t ngx_http_ssi_flastmod_output(ngx_http_request_t *r,
+ void *data, ngx_int_t rc);
static ngx_int_t ngx_http_ssi_echo(ngx_http_request_t *r,
ngx_http_ssi_ctx_t *ctx, ngx_str_t **params);
static ngx_int_t ngx_http_ssi_config(ngx_http_request_t *r,
@@ -308,6 +310,8 @@
ngx_http_ssi_include_params, 0, 0, 1 },
{ ngx_string("fsize"), ngx_http_ssi_fsize,
ngx_http_ssi_fsize_params, 0, 0, 1 },
+ { ngx_string("flastmod"), ngx_http_ssi_fsize,
+ ngx_http_ssi_fsize_params, 0, 0, 1 },
{ ngx_string("echo"), ngx_http_ssi_echo,
ngx_http_ssi_echo_params, 0, 0, 0 },
{ ngx_string("config"), ngx_http_ssi_config,
@@ -2273,14 +2277,14 @@
if (uri && file) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "fsize may be either virtual=\"%V\" or file=\"%V\"",
- uri, file);
+ "%V may be either virtual=\"%V\" or file=\"%V\"",
+ ctx->command, uri, file);
return NGX_HTTP_SSI_ERROR;
}
if (uri == NULL && file == NULL) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "no parameter in \"fsize\" SSI command");
+ "no parameter in \"%V\" SSI command", ctx->command);
return NGX_HTTP_SSI_ERROR;
}
@@ -2309,7 +2313,13 @@
return NGX_ERROR;
}
- psr->handler = ngx_http_ssi_fsize_output;
+ if (ctx->command.len == sizeof("fsize") - 1) {
+ psr->handler = ngx_http_ssi_fsize_output;
+
+ } else if (ctx->command.len == sizeof("flastmod") - 1) {
+ psr->handler = ngx_http_ssi_flastmod_output;
+ }
+
psr->data = ctx;
if (ngx_http_subrequest(r, uri, &args, &sr, psr, flags) != NGX_OK) {
@@ -2402,6 +2412,73 @@
static ngx_int_t
+ngx_http_ssi_flastmod_output(ngx_http_request_t *r, void *data, ngx_int_t rc)
+{
+ size_t len;
+ ngx_buf_t *b;
+ ngx_str_t *timefmt;
+ struct tm tm;
+ ngx_chain_t *out;
+ ngx_http_ssi_ctx_t *ctx;
+
+ ctx = data;
+ timefmt = &ctx->timefmt;
+
+ if (r->request_output) {
+ return rc;
+ }
+
+ if (r->headers_out.last_modified_time == -1) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
+ return NGX_ERROR;
+ }
+
+ b->pos = ctx->errmsg.data;
+ b->last = ctx->errmsg.data + ctx->errmsg.len;
+
+ } else if (timefmt->len == sizeof("%s") - 1
+ && timefmt->data[0] == '%' && timefmt->data[1] == 's')
+ {
+ b = ngx_create_temp_buf(r->pool, NGX_TIME_T_LEN);
+ if (b == NULL) {
+ return NGX_ERROR;
+ }
+
+ b->last = ngx_sprintf(b->last, "%T", r->headers_out.last_modified_time);
+
+ } else {
+ b = ngx_create_temp_buf(r->pool, NGX_HTTP_SSI_DATE_LEN);
+ if (b == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_libc_localtime(r->headers_out.last_modified_time, &tm);
+
+ len = strftime((char *)b->last, NGX_HTTP_SSI_DATE_LEN,
+ (char *) timefmt->data, &tm);
+ if (len == 0) {
+ b->pos = ctx->errmsg.data;
+ b->last = ctx->errmsg.data + ctx->errmsg.len;
+
+ } else {
+ b->last = b->last + len;
+ }
+ }
+
+ out = ngx_alloc_chain_link(r->pool);
+ if (out == NULL) {
+ return NGX_ERROR;
+ }
+
+ out->buf = b;
+ out->next = NULL;
+
+ return ngx_http_output_filter(r, out);
+}
+
+
+static ngx_int_t
ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
ngx_str_t **params)
{
More information about the nginx-devel
mailing list