The MWHttpRequest is implemented by the
CurlHttpRequest class and also the
GuzzleHttpRequest class. However, curl based rendering set
the CURLOPT_POST which implies that the 'Content-Type'
header defaults to 'application/x-www-form-urlencoded'.
To homgonize the functionality this patch mimics the
curl behaviour in Guzzle.
Bug: T232866
Change-Id: Id60a8de18e5f1e750a3bde23bd8b0deca4071165
(cherry picked from commit
5e3a0e73955d6324c5dd6e12fbe36d3ba203d9db)
$this->guzzleOptions['form_params'] = $postData;
} else {
$this->guzzleOptions['body'] = $postData;
$this->guzzleOptions['form_params'] = $postData;
} else {
$this->guzzleOptions['body'] = $postData;
+ // mimic CURLOPT_POST option
+ if ( !isset( $this->reqHeaders['Content-Type'] ) ) {
+ $this->reqHeaders['Content-Type'] = 'application/x-www-form-urlencoded';
+ }
}
// Suppress 'Expect: 100-continue' header, as some servers
}
// Suppress 'Expect: 100-continue' header, as some servers
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
+use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Request;
$this->assertEquals( 404, $r->getStatus() );
$this->assertEquals( 'http-bad-status', $errorMsg );
}
$this->assertEquals( 404, $r->getStatus() );
$this->assertEquals( 'http-bad-status', $errorMsg );
}
+
+ /*
+ * Test of POST requests header
+ */
+ public function testPostBody() {
+ $container = [];
+ $history = Middleware::history( $container );
+ $stack = HandlerStack::create();
+ $stack->push( $history );
+ $client = new GuzzleHttpRequest( $this->exampleUrl, [
+ 'method' => 'POST',
+ 'handler' => $stack,
+ 'post' => 'key=value',
+ ] );
+ $client->execute();
+
+ $request = $container[0]['request'];
+ $this->assertEquals( 'POST', $request->getMethod() );
+ $this->assertEquals( 'application/x-www-form-urlencoded',
+ $request->getHeader( 'Content-Type' )[0] );
+ }