File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -82,11 +82,19 @@ private function createPsr7Request(array $ringPhpRequest)
8282 private function createRingRequest (RequestInterface $ request )
8383 {
8484 $ uri = $ request ->getUri ();
85+ $ body = (string ) $ request ->getBody ();
86+
87+ // RingPHP currently expects empty message bodies to be null:
88+ // https://github.com/guzzle/RingPHP/blob/4c8fe4c48a0fb7cc5e41ef529e43fecd6da4d539/src/Client/CurlFactory.php#L202
89+ if (empty ($ body )) {
90+ $ body = null ;
91+ }
92+
8593 $ ringRequest = [
8694 'http_method ' => $ request ->getMethod (),
8795 'scheme ' => $ uri ->getScheme (),
8896 'uri ' => $ uri ->getPath (),
89- 'body ' => ( string ) $ request -> getBody () ,
97+ 'body ' => $ body ,
9098 'headers ' => $ request ->getHeaders (),
9199 ];
92100 if ($ uri ->getQuery ()) {
Original file line number Diff line number Diff line change @@ -61,6 +61,41 @@ public function testSignsWithProvidedCredentials()
6161 ]);
6262 }
6363
64+ public function testEmptyRequestBodiesShouldBeNull ()
65+ {
66+ $ toWrap = function (array $ ringRequest ) {
67+ $ this ->assertNull ($ ringRequest ['body ' ]);
68+
69+ return $ this ->getGenericResponse ();
70+ };
71+
72+ $ client = $ this ->getElasticsearchClient (
73+ new ElasticsearchPhpHandler ('us-west-2 ' , null , $ toWrap )
74+ );
75+
76+ $ client ->indices ()->exists (['index ' => 'index ' ]);
77+ }
78+
79+ public function testNonEmptyRequestBodiesShouldNotBeNull ()
80+ {
81+ $ toWrap = function (array $ ringRequest ) {
82+ $ this ->assertNotNull ($ ringRequest ['body ' ]);
83+
84+ return $ this ->getGenericResponse ();
85+ };
86+
87+ $ client = $ this ->getElasticsearchClient (
88+ new ElasticsearchPhpHandler ('us-west-2 ' , null , $ toWrap )
89+ );
90+
91+ $ client ->search ([
92+ 'index ' => 'index ' ,
93+ 'body ' => [
94+ 'query ' => [ 'match_all ' => (object )[] ],
95+ ],
96+ ]);
97+ }
98+
6499 private function getElasticsearchClient (ElasticsearchPhpHandler $ handler )
65100 {
66101 $ builder = ClientBuilder::create ()
You can’t perform that action at this time.
0 commit comments