Permalink
Browse files

now more_set_headers supports overriding charset in Content-Type. tha…

…nks ML.
  • Loading branch information...
1 parent 2c629de commit 5fac22379226d3ea51a3d0e5ace74926d43c4d65 @agentzh agentzh committed Jun 16, 2011
Showing with 76 additions and 2 deletions.
  1. +43 −0 src/ngx_http_headers_more_headers_out.c
  2. +22 −1 t/bug.t
  3. +1 −1 util/build.sh
  4. +10 −0 valgrind.suppress
View
43 src/ngx_http_headers_more_headers_out.c
@@ -298,11 +298,54 @@ static ngx_int_t
ngx_http_set_content_type_header(ngx_http_request_t *r, ngx_http_headers_more_header_val_t *hv,
ngx_str_t *value)
{
+ u_char *p, *last, *end;
+
r->headers_out.content_type_len = value->len;
r->headers_out.content_type = *value;
r->headers_out.content_type_hash = hv->hash;
r->headers_out.content_type_lowcase = NULL;
+ p = value->data;
+ end = p + value->len;
+
+ for (; p != end; p++) {
+
+ if (*p != ';') {
+ continue;
+ }
+
+ last = p;
+
+ while (*++p == ' ') { /* void */ }
+
+ if (p == end) {
+ break;
+ }
+
+ if (ngx_strncasecmp(p, (u_char *) "charset=", 8) != 0) {
+ continue;
+ }
+
+ p += 8;
+
+ r->headers_out.content_type_len = last - value->data;
+
+ if (*p == '"') {
+ p++;
+ }
+
+ last = end;
+
+ if (*(last - 1) == '"') {
+ last--;
+ }
+
+ r->headers_out.charset.len = last - p;
+ r->headers_out.charset.data = p;
+
+ break;
+ }
+
value->len = 0;
return ngx_http_set_header_helper(r, hv, value, NULL, 1);
View
23 t/bug.t
@@ -4,7 +4,7 @@ use Test::Nginx::Socket; # 'no_plan';
#repeat_each(2);
-plan tests => 26 * repeat_each();
+plan tests => 29 * repeat_each();
no_diff;
@@ -178,3 +178,24 @@ hello
--- response_body
hello
+
+
+=== TEST 11: override charset
+--- config
+ location /foo {
+ charset iso-8859-1;
+ default_type "text/html";
+ echo hiya;
+ }
+
+ location /bug {
+ more_set_headers "Content-Type: text/html; charset=UTF-8";
+ proxy_pass http://127.0.0.1:$server_port/foo;
+ }
+--- request
+ GET /bug
+--- response_body
+hiya
+--- response_headers
+Content-Type: text/html; charset=UTF-8
+
View
2 util/build.sh
@@ -47,8 +47,8 @@ if [[ "$BUILD_CLEAN" -eq 1 || ! -f Makefile || "$root/config" -nt Makefile || "$
--add-module=$root/../eval-nginx-module \
--add-module=$root/../echo-nginx-module \
--add-module=$root $opts \
- --with-debug \
|| exit 1
+ #--with-debug \
#--add-module=$root/../ndk-nginx-module \
#--without-http_ssi_module # we cannot disable ssi because echo_location_async depends on it (i dunno why?!)
View
10 valgrind.suppress
@@ -78,4 +78,14 @@
fun:ngx_palloc_block
fun:ngx_palloc
}
+{
+ <insert_a_suppression_name_here>
+ Memcheck:Addr8
+ fun:getenv
+ fun:gcov_exit
+ fun:exit
+ fun:ngx_master_process_exit
+ fun:ngx_single_process_cycle
+ fun:main
+}

0 comments on commit 5fac223

Please sign in to comment.