Skip to content

Commit adefb4f

Browse files
committed
mod_negotiation: Do not send the qs parameter in the Content-Type.
A MultiViews response took the media type of the selected file as it was, so the qs source quality set with AddType was sent to the client. Drop it after the variant has been selected. Other parameters are kept. PR 53595.
1 parent f6b14da commit adefb4f

12 files changed

Lines changed: 106 additions & 1 deletion

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*) mod_negotiation: Do not send the "qs" source quality parameter of the selected
2+
variant in the Content-Type of a response negotiated by MultiViews. PR 53595

‎modules/mappers/mod_negotiation.c‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3068,6 +3068,41 @@ static int handle_map_file(request_rec *r)
30683068
return OK;
30693069
}
30703070

3071+
/* The "qs" parameter of a variant's media type is only its source quality
3072+
* for the selection, see get_entry(), and does not belong in the
3073+
* Content-Type of the response. Return content_type without it, all
3074+
* other parameters are kept as they are.
3075+
*/
3076+
static const char *strip_source_quality(apr_pool_t *p,
3077+
const char *content_type)
3078+
{
3079+
const char *line = content_type;
3080+
char *stripped;
3081+
int found = 0;
3082+
3083+
if (!ap_strcasestr(content_type, "qs")) {
3084+
return content_type;
3085+
}
3086+
3087+
stripped = ap_get_token(p, &line, 0);
3088+
while (*line == ';') {
3089+
const char *param = line++;
3090+
const char *name = ap_get_token(p, &line, 1);
3091+
apr_size_t len = strcspn(name, "= \t");
3092+
3093+
if (len == 2 && name[len] && !ap_cstr_casecmpn(name, "qs", 2)) {
3094+
found = 1;
3095+
}
3096+
else {
3097+
stripped = apr_pstrcat(p, stripped,
3098+
apr_pstrmemdup(p, param, line - param),
3099+
NULL);
3100+
}
3101+
}
3102+
3103+
return found ? apr_pstrcat(p, stripped, line, NULL) : content_type;
3104+
}
3105+
30713106
static int handle_multi(request_rec *r)
30723107
{
30733108
negotiation_state *neg;
@@ -3124,6 +3159,14 @@ static int handle_multi(request_rec *r)
31243159
/* now do a "fast redirect" ... promotes the sub_req into the main req */
31253160
ap_internal_fast_redirect(sub_req, r);
31263161

3162+
if (r->content_type) {
3163+
const char *type = strip_source_quality(r->pool, r->content_type);
3164+
3165+
if (type != r->content_type) {
3166+
ap_set_content_type_ex(r, type, AP_REQUEST_IS_TRUSTED_CT(r));
3167+
}
3168+
}
3169+
31273170
/* give no advise for time on this subrequest. Perhaps we
31283171
* should tally the last mtime among all variants, and date
31293172
* the most recent, but that could confuse the proxies.

‎test/pytest_suite/t/conf/extra.conf.in‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@
135135
LanguagePriority zh-TW fr fu en de
136136
</Directory>
137137

138+
<Directory @SERVERROOT@/htdocs/modules/negotiation/qs>
139+
Options +MultiViews
140+
AddType text/html;qs=0.9 .html
141+
AddType application/xhtml+xml;qs=1.0 .xhtml
142+
AddType "text/html;charset=utf-8;qs=0.8" .qsafter
143+
AddType "text/html;QS=0.8;charset=utf-8" .qsbefore
144+
AddType "application/example;foo=\"a;b\";q=0.7;qs=0.5;bar=\"c, d\"" .quoted
145+
</Directory>
146+
138147
<IfDefine APACHE2>
139148
<IfModule @CGI_MODULE@>
140149
<Directory @SERVERROOT@/htdocs/modules/negotiation/query>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
after
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
before
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
html
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
xhtml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
quoted
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
html
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
xht

0 commit comments

Comments
 (0)