diff --git a/main/SAPI.c b/main/SAPI.c index 2e697f9779669..a2bd456d9baf6 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -371,7 +371,7 @@ SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len) charset = SG(default_charset) ? SG(default_charset) : SAPI_DEFAULT_CHARSET; if (*mimetype != NULL) { - if (*charset && strncmp(*mimetype, "text/", 5) == 0 && strstr(*mimetype, "charset=") == NULL) { + if (*charset && strncmp(*mimetype, "text/", 5) == 0 && strstr(*mimetype, "charset=") == NULL && strcmp(*mimetype, "text/event-stream") != 0) { newlen = len + (sizeof(";charset=")-1) + strlen(charset); newtype = emalloc(newlen + 1); PHP_STRLCPY(newtype, *mimetype, newlen + 1, len); diff --git a/sapi/cli/tests/gh11146.phpt b/sapi/cli/tests/gh11146.phpt new file mode 100644 index 0000000000000..20edbcec1a1ca --- /dev/null +++ b/sapi/cli/tests/gh11146.phpt @@ -0,0 +1,45 @@ +--TEST-- +GH-11146: The built-in webserver will add ";charset=UTF-8" to the end of the Content-Type response header of the SSE response. +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +HTTP/1.1 200 OK +Host: %s +Date: %s +Connection: close +X-Powered-By: PHP/%s +Content-Type: text/event-stream + +data: 0 + +data: 1 + +data: 2