Skip to content

Http2 - sendfile failing on safari #4991

@AdamSGit

Description

@AdamSGit

When enabling http2 and using sendfile response method, it fail on safari 16.2 with the error kCFErrorDomainCFNetwork. It work fine on other major browsers.

This issue seem to be caused by the Content-Length header. From my understanding, http2 send 9 bits headers for each chunks of data, which result in incorrect content length size. The quite simple solution to this would be to have the possibility to disable the content-length header in response, which is currently computed automatically.

  1. What did you do? If possible, provide a simple script for reproducing the error.

Please find snippet here (test should have ssl working, as http2 require ssl

// Define server instance
$swoole_server_instance = new Swoole\Http\Server('0.0.0.0', 9010, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL);

// Set server instance attributes
$swoole_server_instance->set([
    'worker_num'             => 4,
    'open_http2_protocol'    => true,
    'ssl_cert_file' => './fullchain.pem',
    'ssl_key_file' => './privkey.pem',
]);

$swoole_server_instance->on('request', static function (Swoole\Http\Request $request, Swoole\Http\Response $response) : void {
    $response->setStatusCode(200);

    $response->header('Content-Type', 'application/pdf');
    $response->sendfile('./test.pdf');
});

// Spin up swoole
$swoole_server_instance->start();
  1. What did you expect to see?
    Safari displaying the pdf as other browsers do

  2. What did you see instead?
    kCFErrorDomainCFNetwork error 303

  3. What version of Swoole are you using (show your php --ri swoole)?

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 5.0.1
Built => Feb 24 2023 18:16:06
coroutine => enabled with boost asm context
kqueue => enabled
rwlock => enabled
openssl => OpenSSL 1.1.1s  1 Nov 2022
dtls => enabled
http2 => enabled
json => enabled
pcre => enabled
zlib => 1.2.11
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 262144 => 262144
  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?
    Darwin MacBook-Pro.local 21.6.0 Darwin Kernel Version 21.6.0: Sun Nov 6 23:31:16 PST 2022; root:xnu-8020.240.14~1/RELEASE_X86_64 x86_64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions