swoole / swoole-src

🚀 Coroutine-based concurrency library for PHP
https://www.swoole.com
Apache License 2.0
18.42k stars 3.16k forks source link

Request header encoding error with exactly 16 lenght #5438

Closed luizmanhani closed 1 month ago

luizmanhani commented 1 month ago

Please answer these questions before submitting your issue.

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

When a request header name has exactly 16 chars length, the request header brokes the encoding name.

script example:

<?php

require_once __DIR__ . '/../vendor/autoload.php';

$http = new Swoole\Http\Server('localhost', 9502);
$http->set(['hook_flags' => SWOOLE_HOOK_ALL]);

$http->on('request', function ($request, $response) {
    var_dump($request->header);
});

$http->start();

request example (the port is because is inside a container):

curl --request GET \
  --url 'http://localhost:9997/?=' \
  --header '0123456789123456: abcdafghijkalmno' \
  --header 'port: 80'
  1. What did you expect to see?

    array(4) {
    ["host"]=>
    string(14) "localhost:9997"
    ["0123456789123456"]=>
    string(16) "abcdafghijkalmno"
    ["port"]=>
    string(2) "80"
    ["accept"]=>
    string(3) "*/*"
    }
  2. What did you see instead?

    
    array(4) {
    ["host"]=>
    string(14) "localhost:9997"
    ["����AmvV"y"]=>
    string(16) "abcdafghijkalmno"
    ["port"]=>
    string(2) "80"
    ["accept"]=>
    string(3) "*/*"
    }

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

swoole

Swoole => enabled Author => Swoole Team team@swoole.com Version => 5.1.2 Built => May 10 2024 13:55:17 coroutine => enabled with boost asm context epoll => enabled eventfd => enabled signalfd => enabled spinlock => enabled rwlock => enabled sockets => enabled openssl => OpenSSL 3.3.0 9 Apr 2024 dtls => enabled http2 => enabled json => enabled curl-native => enabled c-ares => 1.28.1 zlib => 1.3.1 brotli => E16781312/D16781312 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled mysqlnd => enabled async_redis => enabled coroutine_pgsql => enabled coroutine_sqlite => enabled

Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_fiber_mock => Off => Off swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => Off => Off swoole.unixsock_buffer_size => 8388608 => 8388608


6. What is your machine environment used (show your `uname -a` & `php -v` & `gcc -v`) ?

/app # uname -a Linux 75ba64788a16 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64 Linux /app # php -v PHP 8.2.21 (cli) (built: Jul 4 2024 17:07:18) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.21, Copyright (c) Zend Technologies with Zend OPcache v8.2.21, Copyright (c), by Zend Technologies

NathanFreeman commented 1 month ago

Please upgrade to swoole 5.1.3 and give it a try. There is a fix for a request header bug here.

luizmanhani commented 1 month ago

At 6.0.0 it's working, now I am building with 5.1.3 to check and close, thanks for the reply

luizmanhani commented 1 month ago

yeah, fix at 5.1.3 closing...