File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 2424use Elastic \Transport \Serializer \CsvSerializer ;
2525use Elastic \Transport \Serializer \JsonSerializer ;
2626use Elastic \Transport \Serializer \NDJsonSerializer ;
27+ use Elastic \Transport \Serializer \TextSerializer ;
2728use Elastic \Transport \Serializer \XmlSerializer ;
2829use Psr \Http \Message \ResponseInterface ;
2930
@@ -113,6 +114,10 @@ public function asArray(): array
113114 $ this ->asArray = CsvSerializer::unserialize ($ this ->asString ());
114115 return $ this ->asArray ;
115116 }
117+ if (strpos ($ contentType , 'text/plain ' ) !== false ) {
118+ $ this ->asArray = [$ this ->asString ()];
119+ return $ this ->asArray ;
120+ }
116121 throw new UnknownContentTypeException (sprintf (
117122 "Cannot deserialize the reponse as array with Content-Type: %s " ,
118123 $ contentType
Original file line number Diff line number Diff line change @@ -200,4 +200,20 @@ public function testAccessAsObject()
200200
201201 $ this ->assertEquals ($ array ['foo ' ], $ this ->elasticsearch ->foo );
202202 }
203+
204+ /**
205+ * @see https://github.com/elastic/elasticsearch-php/issues/1218
206+ */
207+ public function testAccessAsArrayWithTextPlainResponse ()
208+ {
209+ $ msg = "This is a text/plain response " ;
210+ $ body = $ this ->psr17Factory ->createStream ($ msg );
211+ $ this ->elasticsearch ->setResponse (
212+ $ this ->response200
213+ ->withBody ($ body )
214+ ->withHeader ('Content-Type ' , 'text/plain ' )
215+ );
216+
217+ $ this ->assertEquals ($ msg , $ this ->elasticsearch [0 ]);
218+ }
203219}
You can’t perform that action at this time.
0 commit comments