yii2-httpclient icon indicating copy to clipboard operation
yii2-httpclient copied to clipboard

RFE: please, implement handling return value from beforeSend

Open dicrtarasov opened this issue 5 years ago • 2 comments

In StreamTransport::send()

public function send($request)
{
    $request->beforeSend();
    $request->prepare();
    ...

Also in Request::beforeSend()

public function beforeSend()
{
    $this->client->beforeSend($this);
    $event = new RequestEvent();
    ...

We need to handle return value from beforeSend to cancel sending, like ActiveRecord do:

protected function updateInternal($attributes = null)
{
    if (!$this->beforeSave(false)) {
        return false;
    }
    ...

For ex. I want to implement response caching behavior for Client. So, if response is already in cache, then onBeforeSend return false and sending must stop.

dicrtarasov avatar Feb 07 '20 15:02 dicrtarasov

Sounds good. Can be released in 2.1.0 since it changes existing behavior.

samdark avatar Feb 07 '20 21:02 samdark

Existing implementations return void, so, checking === false ..... Thank you :)

dicrtarasov avatar Feb 08 '20 02:02 dicrtarasov