Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mod_xmlenc: update to accept any XML media type per RFC 7303 #409

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions modules/filters/mod_xml2enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ static apr_status_t xml2enc_ffunc(ap_filter_t* f, apr_bucket_brigade* bb)
apr_bucket* bstart;
apr_size_t insz = 0;
int pending_meta = 0;
char *ctype;
char *mtype;
char *p;

if (!ctx || !f->r->content_type) {
Expand All @@ -338,13 +338,17 @@ static apr_status_t xml2enc_ffunc(ap_filter_t* f, apr_bucket_brigade* bb)
return ap_pass_brigade(f->next, bb) ;
}

ctype = apr_pstrdup(f->r->pool, f->r->content_type);
for (p = ctype; *p; ++p)
if (isupper(*p))
*p = tolower(*p);

/* only act if starts-with "text/" or contains "+xml" */
if (strncmp(ctype, "text/", 5) && !strstr(ctype, "+xml")) {
/* Extract the media type, ignoring parameters in content-type. */
mtype = apr_pstrdup(f->r->pool, f->r->content_type);
if ((p = ap_strchr(mtype, ';')) != NULL) *p = '\0';
ap_str_tolower(mtype);

/* Accept text/ types, plus any XML media type per RFC 7303. */
if (!(strncmp(mtype, "text/", 5) == 0
|| strcmp(mtype, "application/xml") == 0
|| (strlen(mtype) > 7 /* minimum 'a/b+xml' length */
&& (p = strstr(mtype, "+xml")) != NULL
&& strlen(p) == 4 /* ensures +xml is a suffix */))) {
ap_remove_output_filter(f);
return ap_pass_brigade(f->next, bb) ;
}
Expand Down
Loading