[PATCH] Add autoindex_css_file option
Clément Bœsch
ubitux at gmail.com
Sun Feb 20 20:08:29 MSK 2011
On Sun, Feb 20, 2011 at 06:03:45PM +0100, Clément Bœsch wrote:
> From d3c3318d570091ca0920363c0178e53b2f4eaa76 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
> Date: Sun, 20 Feb 2011 17:57:03 +0100
> Subject: [PATCH] Add autoindex_css_file option.
>
[...]
Sorry wrong patch, I removed the <body> tag in the process; fixed.
--
Clément B.
-------------- next part --------------
From b53ffc36aaf19be656cbb5d87956727a43c3c815 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
Date: Sun, 20 Feb 2011 17:57:03 +0100
Subject: [PATCH] Add autoindex_css_file option.
---
src/http/modules/ngx_http_autoindex_module.c | 47 ++++++++++++++++++++++++--
1 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/src/http/modules/ngx_http_autoindex_module.c b/src/http/modules/ngx_http_autoindex_module.c
index b679318..eace189 100644
--- a/src/http/modules/ngx_http_autoindex_module.c
+++ b/src/http/modules/ngx_http_autoindex_module.c
@@ -39,6 +39,7 @@ typedef struct {
ngx_flag_t enable;
ngx_flag_t localtime;
ngx_flag_t exact_size;
+ ngx_str_t css_file;
} ngx_http_autoindex_loc_conf_t;
@@ -80,6 +81,13 @@ static ngx_command_t ngx_http_autoindex_commands[] = {
offsetof(ngx_http_autoindex_loc_conf_t, exact_size),
NULL },
+ { ngx_string("autoindex_css_file"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_str_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_autoindex_loc_conf_t, css_file),
+ NULL },
+
ngx_null_command
};
@@ -120,6 +128,34 @@ static u_char title[] =
"<head><title>Index of "
;
+static u_char title_pre_css[] =
+"<html>" CRLF
+"<head><link rel=\"stylesheet\" type=\"text/css\" href=\""
+;
+
+static u_char title_post_css[] = "\" /><title>Index of ";
+
+static void
+ngx_http_autoindex_get_hdr(ngx_log_t *log, ngx_str_t *dst, ngx_str_t *css_file)
+{
+ if (!css_file->len)
+ goto no_custom_css;
+
+ dst->len = sizeof(title_pre_css) - 1
+ + css_file->len
+ + sizeof(title_post_css) - 1;
+ dst->data = ngx_alloc(dst->len + 1, log);
+ if (!dst->data)
+ goto no_custom_css;
+
+ ngx_sprintf(dst->data, "%s%s%s", title_pre_css, css_file->data,
+ title_post_css);
+ return;
+
+no_custom_css:
+ dst->data = title;
+ dst->len = sizeof(title) - 1;
+}
static u_char header[] =
"</title></head>" CRLF
@@ -143,7 +179,7 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
ngx_err_t err;
ngx_buf_t *b;
ngx_int_t rc, size;
- ngx_str_t path;
+ ngx_str_t path, html_hdr;
ngx_dir_t dir;
ngx_uint_t i, level, utf8;
ngx_pool_t *pool;
@@ -358,7 +394,9 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
ngx_close_dir_n " \"%s\" failed", &path);
}
- len = sizeof(title) - 1
+ ngx_http_autoindex_get_hdr(r->connection->log, &html_hdr, &alcf->css_file);
+
+ len = html_hdr.len
+ r->uri.len
+ sizeof(header) - 1
+ r->uri.len
@@ -392,7 +430,7 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
ngx_http_autoindex_cmp_entries);
}
- b->last = ngx_cpymem(b->last, title, sizeof(title) - 1);
+ b->last = ngx_cpymem(b->last, html_hdr.data, html_hdr.len);
b->last = ngx_cpymem(b->last, r->uri.data, r->uri.len);
b->last = ngx_cpymem(b->last, header, sizeof(header) - 1);
b->last = ngx_cpymem(b->last, r->uri.data, r->uri.len);
@@ -633,6 +671,8 @@ ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf)
conf->enable = NGX_CONF_UNSET;
conf->localtime = NGX_CONF_UNSET;
conf->exact_size = NGX_CONF_UNSET;
+ conf->css_file.len = 0;
+ conf->css_file.data = NULL;
return conf;
}
@@ -647,6 +687,7 @@ ngx_http_autoindex_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->enable, prev->enable, 0);
ngx_conf_merge_value(conf->localtime, prev->localtime, 0);
ngx_conf_merge_value(conf->exact_size, prev->exact_size, 1);
+ ngx_conf_merge_str_value(conf->css_file, prev->css_file, "");
return NGX_CONF_OK;
}
--
1.7.4.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://nginx.org/pipermail/nginx-devel/attachments/20110220/feb4ff6c/attachment.pgp>
More information about the nginx-devel
mailing list