Skip to content
This repository has been archived by the owner on May 31, 2022. It is now read-only.

[BUG] Base64 string instead of decoded payload #86

Closed
Yurunsoft opened this issue Oct 22, 2021 · 6 comments · Fixed by #88
Closed

[BUG] Base64 string instead of decoded payload #86

Yurunsoft opened this issue Oct 22, 2021 · 6 comments · Fixed by #88
Assignees
Labels
B-regression Bug: regression bugs P-HTTP Plugin: HTTP
Milestone

Comments

@Yurunsoft
Copy link

I tried this code:

.rr.yaml:

server:
  command: "php rr.php"

http:
  address: 0.0.0.0:13000
  pool:
    num_workers: 2

rpc:
  listen: tcp://127.0.0.1:6001

rr.php:

<?php

declare(strict_types=1);

use Nyholm\Psr7;
use Spiral\RoadRunner;

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

$worker = RoadRunner\Worker::create();
$psrFactory = new Psr7\Factory\Psr17Factory();

$worker = new RoadRunner\Http\PSR7Worker($worker, $psrFactory, $psrFactory, $psrFactory);

while ($req = $worker->waitRequest())
{
    try
    {
        $rsp = new Psr7\Response();
        $rsp->getBody()->write((string) $req->getBody());

        $worker->respond($rsp);
    }
    catch (\Throwable $e)
    {
        $worker->getWorker()->error((string) $e);
    }
}

client.php:

$curl = curl_init();

// First post
curl_setopt_array($curl, [
    \CURLOPT_URL            => 'http://127.0.0.1:13000/',
    \CURLOPT_RETURNTRANSFER => true,
    \CURLOPT_ENCODING       => '',
    \CURLOPT_MAXREDIRS      => 10,
    \CURLOPT_TIMEOUT        => 0,
    \CURLOPT_FOLLOWLOCATION => true,
    \CURLOPT_HTTP_VERSION   => \CURL_HTTP_VERSION_1_1,
    \CURLOPT_CUSTOMREQUEST  => 'POST',
    \CURLOPT_POSTFIELDS     => ['a' => 1],
    \CURLOPT_HTTPHEADER     => [
    ],
]);
$response = curl_exec($curl);
var_dump($response);

// Then json post
do
{
    curl_setopt_array($curl, [
        \CURLOPT_URL            => 'http://127.0.0.1:13000/',
        \CURLOPT_RETURNTRANSFER => true,
        \CURLOPT_ENCODING       => '',
        \CURLOPT_MAXREDIRS      => 10,
        \CURLOPT_TIMEOUT        => 0,
        \CURLOPT_FOLLOWLOCATION => true,
        \CURLOPT_HTTP_VERSION   => \CURL_HTTP_VERSION_1_1,
        \CURLOPT_CUSTOMREQUEST  => 'POST',
        \CURLOPT_POSTFIELDS     => '{"a":2}',
        \CURLOPT_HTTPHEADER     => [
            'Content-Type: application/json',
        ],
    ]);
    $response = curl_exec($curl);
    var_dump($response);
}
while ('"eyJhIjoyfQ=="' !== $response);

curl_close($curl);

Possible outputs:

string(9) "{"a":"1"}"
string(7) "{"a":2}"
string(7) "{"a":2}"
string(7) "{"a":2}"
string(7) "{"a":2}"
string(7) "{"a":2}"
string(7) "{"a":2}"
string(7) "{"a":2}"
string(7) "{"a":2}"
string(7) "{"a":2}"
string(14) ""eyJhIjoyfQ==""

When a non JSON request is first posted and then a JSON request is posted, the probability of "eyJhIjoyfQ==" will appear

This bug only occurs in v2.5.0

@rustatian
Copy link
Member

Hey @Yurunsoft . eyJhIjoyfQ== is actually base64 for the "{"a":2}". I'm not actually sure, where it comes from, but I'll check.

@rustatian rustatian changed the title [BUG] POST JSON [BUG] Base64 string instead of decoded payload Oct 22, 2021
@rustatian
Copy link
Member

rustatian commented Oct 22, 2021

Yes @Yurunsoft I can confirm, this is the bug. It Will be resolved ASAP and fixed in 2.5.1

@rustatian
Copy link
Member

I'll transfer this issue to the rr-plugins repo

@rustatian rustatian transferred this issue from roadrunner-server/roadrunner Oct 22, 2021
@rustatian rustatian added B-regression Bug: regression bugs P-HTTP Plugin: HTTP labels Oct 22, 2021
@rustatian rustatian added this to the v2.5.1 milestone Oct 22, 2021
@rustatian
Copy link
Member

@Yurunsoft Found the issue, the fix will be in a few hours.

RoadRunner automation moved this from To do to Done Oct 22, 2021
@rustatian
Copy link
Member

@Yurunsoft
Copy link
Author

Thanks~

@rustatian rustatian removed this from SPRINT 2021-11-29 [DONE] in RoadRunner Sprints Jan 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
B-regression Bug: regression bugs P-HTTP Plugin: HTTP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants