@@ -59,6 +59,7 @@ APLOG_USE_MODULE(http);
59
59
60
60
static apr_bucket * create_trailers_bucket (request_rec * r , apr_bucket_alloc_t * bucket_alloc );
61
61
static apr_bucket * create_response_bucket (request_rec * r , apr_bucket_alloc_t * bucket_alloc );
62
+ static void merge_response_headers (request_rec * r );
62
63
63
64
typedef struct http_filter_ctx
64
65
{
@@ -1239,12 +1240,16 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f,
1239
1240
ap_log_rerror (APLOG_MARK , APLOG_TRACE3 , 0 , r ,
1240
1241
"ap_http_header_filter prep response status %d" ,
1241
1242
r -> status );
1243
+ merge_response_headers (r );
1242
1244
if (!check_headers (r )) {
1243
1245
/* We may come back here from ap_die() below,
1244
1246
* so clear anything from this response.
1245
1247
*/
1246
1248
apr_table_clear (r -> headers_out );
1247
1249
apr_table_clear (r -> err_headers_out );
1250
+ r -> content_type = r -> content_encoding = NULL ;
1251
+ r -> content_languages = NULL ;
1252
+ r -> clength = r -> chunked = 0 ;
1248
1253
apr_brigade_cleanup (b );
1249
1254
1250
1255
/* Don't recall ap_die() if we come back here (from its own internal
@@ -1261,8 +1266,6 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f,
1261
1266
APR_BRIGADE_INSERT_TAIL (b , e );
1262
1267
e = apr_bucket_eos_create (c -> bucket_alloc );
1263
1268
APR_BRIGADE_INSERT_TAIL (b , e );
1264
- r -> content_type = r -> content_encoding = NULL ;
1265
- r -> content_languages = NULL ;
1266
1269
ap_set_content_length (r , 0 );
1267
1270
recursive_error = 1 ;
1268
1271
}
@@ -2044,7 +2047,7 @@ static const char *get_status_reason(const char *status_line)
2044
2047
return NULL ;
2045
2048
}
2046
2049
2047
- static apr_bucket * create_response_bucket (request_rec * r , apr_bucket_alloc_t * bucket_alloc )
2050
+ static void merge_response_headers (request_rec * r )
2048
2051
{
2049
2052
const char * ctype ;
2050
2053
@@ -2056,6 +2059,7 @@ static apr_bucket *create_response_bucket(request_rec *r, apr_bucket_alloc_t *bu
2056
2059
if (!apr_is_empty_table (r -> err_headers_out )) {
2057
2060
r -> headers_out = apr_table_overlay (r -> pool , r -> err_headers_out ,
2058
2061
r -> headers_out );
2062
+ apr_table_clear (r -> err_headers_out );
2059
2063
}
2060
2064
2061
2065
ap_set_std_response_headers (r );
@@ -2077,6 +2081,9 @@ static apr_bucket *create_response_bucket(request_rec *r, apr_bucket_alloc_t *bu
2077
2081
fixup_vary (r );
2078
2082
}
2079
2083
2084
+ /* Determine the protocol and whether we should use keepalives. */
2085
+ basic_http_header_check (r );
2086
+
2080
2087
/*
2081
2088
* Now remove any ETag response header field if earlier processing
2082
2089
* says so (such as a 'FileETag None' directive).
@@ -2085,10 +2092,19 @@ static apr_bucket *create_response_bucket(request_rec *r, apr_bucket_alloc_t *bu
2085
2092
apr_table_unset (r -> headers_out , "ETag" );
2086
2093
}
2087
2094
2088
- /* determine the protocol and whether we should use keepalives. */
2089
- basic_http_header_check (r );
2095
+ /*
2096
+ * Control cachability for non-cacheable responses if not already set by
2097
+ * some other part of the server configuration.
2098
+ */
2099
+ if (r -> no_cache && !apr_table_get (r -> headers_out , "Expires" )) {
2100
+ char * date = apr_palloc (r -> pool , APR_RFC822_DATE_LEN );
2101
+ ap_recent_rfc822_date (date , r -> request_time );
2102
+ apr_table_addn (r -> headers_out , "Expires" , date );
2103
+ }
2090
2104
2105
+ /* 204/304 responses don't have content related headers */
2091
2106
if (AP_STATUS_IS_HEADER_ONLY (r -> status )) {
2107
+ apr_table_unset (r -> headers_out , "Transfer-Encoding" );
2092
2108
apr_table_unset (r -> headers_out , "Content-Length" );
2093
2109
r -> content_type = r -> content_encoding = NULL ;
2094
2110
r -> content_languages = NULL ;
@@ -2124,17 +2140,10 @@ static apr_bucket *create_response_bucket(request_rec *r, apr_bucket_alloc_t *bu
2124
2140
field = apr_array_pstrcat (r -> pool , r -> content_languages , ',' );
2125
2141
apr_table_setn (r -> headers_out , "Content-Language" , field );
2126
2142
}
2143
+ }
2127
2144
2128
- /*
2129
- * Control cachability for non-cacheable responses if not already set by
2130
- * some other part of the server configuration.
2131
- */
2132
- if (r -> no_cache && !apr_table_get (r -> headers_out , "Expires" )) {
2133
- char * date = apr_palloc (r -> pool , APR_RFC822_DATE_LEN );
2134
- ap_recent_rfc822_date (date , r -> request_time );
2135
- apr_table_addn (r -> headers_out , "Expires" , date );
2136
- }
2137
-
2145
+ static apr_bucket * create_response_bucket (request_rec * r , apr_bucket_alloc_t * bucket_alloc )
2146
+ {
2138
2147
/* r->headers_out fully prepared. Create a headers bucket
2139
2148
* containing the response to send down the filter chain.
2140
2149
*/
0 commit comments