title: How to modify parameters in Guzzle middleware?
body: <p>I want to write a middleware for <a href="https://github.com/guzzle/guzzle" rel="nofollow">Guzzle</a> that adds a specific key to the <code>form_params</code> and populates it with a value. In the docs I have read <a href="http://docs.guzzlephp.org/en/latest/handlers-and-middleware.html#middleware" rel="nofollow">how to modify the headers</a> but have not found anything about other properties of the <code>$request</code> object. Following the example from the docs this is what I have:</p>
  
  <pre><code>$key = 'asdf';
  
  $stack = new HandlerStack();
  $stack-&gt;setHandler(new CurlHandler());
  $stack-&gt;push(Middleware::mapRequest(function (RequestInterface $request) use ($key) {
  
      // TODO: Modify the $request so that
      // $form_params['api_key'] == 'default_value'
  
      return $request;
  }));
  
  $client = new Client(array(
      'handler' =&gt; $stack
  ));
  </code></pre>
  
  <p>The middleware should modify the request so that this:</p>
  
  <pre><code>$client-&gt;post('example', array(
      'form_params' =&gt; array(
          'foo' =&gt; 'some_value'
      )
  ));
  </code></pre>
  
  <p>has the same effect as this:</p>
  
  <pre><code>$client-&gt;post('example', array(
      'form_params' =&gt; array(
          'foo' =&gt; 'some_value',
          'api_key' =&gt; 'default_value'
      )
  ));
  </code></pre>