@@ -8,7 +8,7 @@ static ngx_int_t ngx_http_redirectionio_header_read(ngx_http_request_t *r, ngx_t
8
8
9
9
static ngx_int_t ngx_http_redirectionio_header_content_type_read (ngx_http_request_t * r , struct REDIRECTIONIO_HeaderMap * * first );
10
10
11
- static ngx_int_t ngx_http_redirectionio_header_content_type_write (ngx_http_request_t * r , ngx_table_elt_t * h );
11
+ static ngx_int_t ngx_http_redirectionio_header_content_type_write (ngx_http_request_t * r , u_char * value );
12
12
13
13
static ngx_int_t ngx_http_redirectionio_buffer_read (ngx_buf_t * buffer , struct REDIRECTIONIO_Buffer * output );
14
14
@@ -147,6 +147,14 @@ ngx_int_t ngx_http_redirectionio_headers_filter(ngx_http_request_t *r) {
147
147
continue ;
148
148
}
149
149
150
+ // Some header should not be written into the headers list of the response, and in some special fields instead
151
+ if (ngx_strcasecmp ((u_char * )header_map -> name , (u_char * )"Content-Type" ) == 0 ) {
152
+ ngx_http_redirectionio_header_content_type_write (r , (u_char * )header_map -> value );
153
+ header_map = header_map -> next ;
154
+
155
+ continue ;
156
+ }
157
+
150
158
h = ngx_list_push (& r -> headers_out .headers );
151
159
152
160
if (h == NULL ) {
@@ -167,12 +175,13 @@ ngx_int_t ngx_http_redirectionio_headers_filter(ngx_http_request_t *r) {
167
175
168
176
ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 , "http redirectionio add header to response \"%s: %s\"" , header_map -> name , header_map -> value );
169
177
178
+ // Some headers need to be set in some special fields
170
179
if (ngx_strcasecmp ((u_char * )header_map -> name , (u_char * )"Content-Encoding" ) == 0 ) {
171
180
r -> headers_out .content_encoding = h ;
172
181
}
173
182
174
- if (ngx_strcasecmp ((u_char * )header_map -> name , (u_char * )"Content-Type " ) == 0 ) {
175
- ngx_http_redirectionio_header_content_type_write ( r , h ) ;
183
+ if (ngx_strcasecmp ((u_char * )header_map -> name , (u_char * )"Server " ) == 0 ) {
184
+ r -> headers_out . server = h ;
176
185
}
177
186
178
187
header_map = header_map -> next ;
@@ -456,15 +465,18 @@ static ngx_int_t ngx_http_redirectionio_header_content_type_read(ngx_http_reques
456
465
return NGX_OK ;
457
466
}
458
467
459
- static ngx_int_t ngx_http_redirectionio_header_content_type_write (ngx_http_request_t * r , ngx_table_elt_t * h ) {
468
+ static ngx_int_t ngx_http_redirectionio_header_content_type_write (ngx_http_request_t * r , u_char * value ) {
460
469
u_char * p , * last ;
470
+ size_t value_len = strlen ((const char * )value );
461
471
462
- r -> headers_out .content_type_len = h -> value .len ;
463
- r -> headers_out .content_type = h -> value ;
464
- r -> headers_out .content_type_lowcase = NULL ;
472
+ r -> headers_out .content_type_len = value_len ;
473
+ r -> headers_out .content_type .len = value_len ;
474
+ r -> headers_out .content_type .data = ngx_pcalloc (r -> pool , value_len );
475
+ ngx_memcpy (r -> headers_out .content_type .data , value , value_len );
465
476
466
- for ( p = h -> value . data ; * p ; p ++ ) {
477
+ r -> headers_out . content_type_lowcase = NULL ;
467
478
479
+ for (p = value ; * p != '\0' ; p ++ ) {
468
480
if (* p != ';' ) {
469
481
continue ;
470
482
}
@@ -483,13 +495,13 @@ static ngx_int_t ngx_http_redirectionio_header_content_type_write(ngx_http_reque
483
495
484
496
p += 8 ;
485
497
486
- r -> headers_out .content_type_len = last - h -> value . data ;
498
+ r -> headers_out .content_type_len = last - value ;
487
499
488
500
if (* p == '"' ) {
489
501
p ++ ;
490
502
}
491
503
492
- last = h -> value . data + h -> value . len ;
504
+ last = value + value_len ;
493
505
494
506
if (* (last - 1 ) == '"' ) {
495
507
last -- ;
0 commit comments