# HG changeset patch # User Maxim Dounin # Date 1341792786 0 # Node ID 192f54280a7aa85168b3d3f1c000951bb9305309 # Parent 1e2ac45ad25de1138e77357afb02264576623102 Entity tags: set for static respones. diff --git a/src/http/modules/ngx_http_flv_module.c b/src/http/modules/ngx_http_flv_module.c --- a/src/http/modules/ngx_http_flv_module.c +++ b/src/http/modules/ngx_http_flv_module.c @@ -194,6 +194,10 @@ ngx_http_flv_handler(ngx_http_request_t r->headers_out.content_length_n = len; r->headers_out.last_modified_time = of.mtime; + if (ngx_http_set_etag(r) != NGX_OK) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + if (ngx_http_set_content_type(r) != NGX_OK) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } diff --git a/src/http/modules/ngx_http_gzip_static_module.c b/src/http/modules/ngx_http_gzip_static_module.c --- a/src/http/modules/ngx_http_gzip_static_module.c +++ b/src/http/modules/ngx_http_gzip_static_module.c @@ -207,6 +207,10 @@ ngx_http_gzip_static_handler(ngx_http_re r->headers_out.content_length_n = of.size; r->headers_out.last_modified_time = of.mtime; + if (ngx_http_set_etag(r) != NGX_OK) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + if (ngx_http_set_content_type(r) != NGX_OK) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } diff --git a/src/http/modules/ngx_http_mp4_module.c b/src/http/modules/ngx_http_mp4_module.c --- a/src/http/modules/ngx_http_mp4_module.c +++ b/src/http/modules/ngx_http_mp4_module.c @@ -586,6 +586,10 @@ ngx_http_mp4_handler(ngx_http_request_t r->headers_out.status = NGX_HTTP_OK; r->headers_out.last_modified_time = of.mtime; + if (ngx_http_set_etag(r) != NGX_OK) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + if (ngx_http_set_content_type(r) != NGX_OK) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } diff --git a/src/http/modules/ngx_http_static_module.c b/src/http/modules/ngx_http_static_module.c --- a/src/http/modules/ngx_http_static_module.c +++ b/src/http/modules/ngx_http_static_module.c @@ -220,6 +220,10 @@ ngx_http_static_handler(ngx_http_request r->headers_out.content_length_n = of.size; r->headers_out.last_modified_time = of.mtime; + if (ngx_http_set_etag(r) != NGX_OK) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + if (ngx_http_set_content_type(r) != NGX_OK) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -1809,6 +1809,35 @@ ngx_http_set_exten(ngx_http_request_t *r ngx_int_t +ngx_http_set_etag(ngx_http_request_t *r) +{ + ngx_table_elt_t *etag; + + etag = ngx_list_push(&r->headers_out.headers); + if (etag == NULL) { + return NGX_ERROR; + } + + etag->hash = 1; + ngx_str_set(&etag->key, "ETag"); + + etag->value.data = ngx_pnalloc(r->pool, NGX_OFF_T_LEN + NGX_TIME_T_LEN + 3); + if (etag->value.data == NULL) { + return NGX_ERROR; + } + + etag->value.len = ngx_sprintf(etag->value.data, "\"%xT-%xO\"", + r->headers_out.last_modified_time, + r->headers_out.content_length_n) + - etag->value.data; + + r->headers_out.etag = etag; + + return NGX_OK; +} + + +ngx_int_t ngx_http_send_response(ngx_http_request_t *r, ngx_uint_t status, ngx_str_t *ct, ngx_http_complex_value_t *cv) { diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -480,6 +480,7 @@ ngx_int_t ngx_http_core_content_phase(ng void *ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash); ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r); void ngx_http_set_exten(ngx_http_request_t *r); +ngx_int_t ngx_http_set_etag(ngx_http_request_t *r); ngx_int_t ngx_http_send_response(ngx_http_request_t *r, ngx_uint_t status, ngx_str_t *ct, ngx_http_complex_value_t *cv); u_char *ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *name,