-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Http2 - sendfile failing on safari #4991
Comments
I can not reproduce it. |
I tested with multiples pdf, jpg and svg files from size starting to 80ko up to 3mo, the result is the same. Weird that you can't reproduce it. Your test environment share the same safari version and swoole build options ? |
I was going to write about it. I found the same bug in Safari 15 and 17 while finding out that a specific js file wasn't being served on my website. I found out that it actually happens when I send anything over ~70kb. Only the start of the file is able to transfer (~47kb) and then the loading bar seems to infinitely wait for the server while on the console in Safari 15 I have an "kCFErrorDomainCFNetwork error 303" error, on Safari 17 the error is "Failed to load resource: cannot parse response." Ofc I don't have this problem when Safari uses HTTP1.1. Swoole version:
|
I managed to reproduce the error by copy/pasting Adam's snippet, "worker_num" doesn't really matter it seems, and instead of sending a file I just sent a text over 65.6kb in size. <?php
// Define server instance
$swoole_server_instance = new Swoole\Http\Server('0.0.0.0', 443, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL);
// Set server instance attributes
$swoole_server_instance->set([
'worker_num' => 1,
'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->end(<<<'DATA'
[>65.6kb text here]
DATA);
});
// Spin up swoole
$swoole_server_instance->start();
?> |
Here's a tcpdump of the entire communication between Swoole and Safari 17 when I tried to serve 65.7kb of text.
I think that for those who understand all that they can figure out where the problem lies. (I don't understand what I'm seeing yet) |
When enabling http2 and using
sendfile
response method, it fail on safari 16.2 with the errorkCFErrorDomainCFNetwork
. 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.Please find snippet here (test should have ssl working, as http2 require ssl
What did you expect to see?
Safari displaying the pdf as other browsers do
What did you see instead?
kCFErrorDomainCFNetwork error 303
What version of Swoole are you using (show your
php --ri swoole
)?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
The text was updated successfully, but these errors were encountered: