php / php/php-src

SAPI should not add charset to each text subtype

Open
#11,146 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Category: SAPI Feature
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The built-in webserver will add ";charset=UTF-8" to the end of the Content-Type response header of the SSE response

The following code:

<?php
header('Content-Type: text/event-stream');
for ($i = 0; $i < 3; ++$i) {
    echo 'data: ' . $i . "\n\n";
}

Run server:

php -S 127.0.0.1:8080 test.php

Test:

curl http://127.0.0.1:8080/ -vvv

Resulted in this output:

# curl http://127.0.0.1:8080/ -vvv
*   Trying 127.0.0.1:8080...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Host: 127.0.0.1:8080
< Date: Fri, 28 Apr 2023 02:51:28 GMT
< Connection: close
< X-Powered-By: PHP/8.1.18
< Content-type: text/event-stream;charset=UTF-8
<
data: 0

data: 1

data: 2

* Closing connection 0

But I expected this output instead:

# curl http://127.0.0.1:8080/ -vvv
*   Trying 127.0.0.1:8080...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Host: 127.0.0.1:8080
< Date: Fri, 28 Apr 2023 02:51:28 GMT
< Connection: close
< X-Powered-By: PHP/8.1.18
< Content-type: text/event-stream
<
data: 0

data: 1

data: 2

* Closing connection 0
PHP Version

PHP 8.0.28, 8.1.18, 8.2.5

Operating System

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the built-in webserver response with the PHP script and curl command shown in the issue, then trace the SAPI response-header handling for text/event-stream. Done means the response preserves Content-Type: text/event-stream without the automatically appended charset, with the existing SSE body still returned.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
backend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.