Giter Club home page Giter Club logo

guzzlebundleheaderforwardplugin's People

Contributors

neirda24 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

guzzlebundleheaderforwardplugin's Issues

Remove composer.lock

My suggestion is to remove composer.lock and add it to .gitignore. It's good practice and it will give you possibility to work always with latest versions of dependencies.

Empty request stack forces an exception

If request stack is empty, the plugin throws an exception:

In GuzzleForwardHeaderMiddleware.php line 48:
                                                          
  [ErrorException]                                        
  Notice: Trying to get property 'headers' of non-object  

This is because the plugin does not check if the current request is null:

src/GuzzleForwardHeaderMiddleware.php:

    public function __invoke(callable $handler): callable
    {
        return function(RequestInterface $request, array $options) use (&$handler) {
            if (empty($this->headers)) {
                return $handler;
            }

            $currentRequest = $this->requestStack->getCurrentRequest(); // <<===

            foreach ($this->headers as $header) {
                if ($currentRequest->headers->has($header)) {
                    $request = $request->withHeader($header, $currentRequest->headers->get($header));
                }
            }

            return $handler($request, $options);
        };
    }
    /**
     * @return Request|null
     */
    public function getCurrentRequest() { … }

You'd better do this:

    public function __invoke(callable $handler): callable
    {
        return function(RequestInterface $request, array $options) use (&$handler) {
            if (empty($this->headers)) {
                return $handler;
            }

            $currentRequest = $this->requestStack->getCurrentRequest(); // <<===

            if (null !== $currentRequest) {
                foreach ($this->headers as $header) {
                    if ($currentRequest->headers->has($header)) {
                        $request = $request->withHeader($header, $currentRequest->headers->get($header));
                    }
                }
            }

            return $handler($request, $options);
        };
    }

How to reproduce:
Create a custom Symfony command, that triggers a Guzzle request, and fire the command from the console (no http request => no request stack).

Support PHP 8

Issue during instalation:

Package neirda24/guzzle-bundle-header-forward-plugin has requirements incompatible with your PHP version, PHP extensions and Composer version:  
    - neirda24/guzzle-bundle-header-forward-plugin 2.0.0 requires php ^7.0 which does not match your installed version 8.1.16.                    
                                                                                                                                   

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.