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

Http Client duplucate effort when attaching "beforeSending" closure callback #37105

Closed
hubseven opened this issue Apr 23, 2021 · 0 comments · Fixed by #37116
Closed

Http Client duplucate effort when attaching "beforeSending" closure callback #37105

hubseven opened this issue Apr 23, 2021 · 0 comments · Fixed by #37116

Comments

@hubseven
Copy link

  • Laravel Version: 8.38.0
  • PHP Version: 8.0.2
  • Database Driver & Version: mysql 5.7

Description:

When making HTTP requests using Http Client its possible to add a closure to the PendingRequest object using the beforeSending method. This adds a closure callback that is run after the http request has been made.

The closure is executed twice causing unintended side effects.

Steps To Reproduce:

Run the following code

Http::beforeSending(function($request, $options) {
    \Log::info('Preprocessing');
})->get('example.org');

Inspect the log to see 2 entries for "Preprocessing"

A workaround

Http::beforeSending(function($request, $options) {
    static $isProcessed = false;
    $isProcessed && \Log::info('Preprocessing');
    $isProcessed = true;
})->get('example.org');
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 a pull request may close this issue.

1 participant