Skip to content
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

fix Swoole\Coroutine\Http\Client->setCookies() bug #2644

Merged
merged 3 commits into from
Jun 24, 2019

Conversation

Yurunsoft
Copy link
Member

下面代码 test() 方法注释处,当第一个请求有Set-Cookie 时,第二次请求输出不是空数组。

<?php
function test()
{
    $result = [];
    // 第二次执行,我都赋值为[]了,还输出被 Swoole\Coroutine\Http\Client 改变了的值
    var_dump($result);
    return $result;
}

go(function(){
    $client = new Swoole\Coroutine\Http\Client('httpbin.org', 80);
    $client->setMethod('GET');
    $cookies = test();
    $client->setCookies($cookies);
    $client->execute('/cookies/set/a/1');

    $client->setMethod('GET');
    $cookies = test();
    $client->setCookies($cookies);
    $client->execute('/cookies');

});

@matyhtf
Copy link
Member

matyhtf commented Jun 24, 2019

这改变了 API 定义。

setCookies API 是 merge cookie,但是不会清空。可以使用设置 key 为 null 的方式清理掉 cookie

@Yurunsoft
Copy link
Member Author

merge到一个新变量,但是不影响我上面贴的代码里的$result,这样是否可行。

现在这个方法第二次$result = [];值都不对了,这肯定是有问题的。

@twose twose merged commit 07114ac into swoole:master Jun 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants