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 24
24
use Elastic \Transport \Serializer \CsvSerializer ;
25
25
use Elastic \Transport \Serializer \JsonSerializer ;
26
26
use Elastic \Transport \Serializer \NDJsonSerializer ;
27
+ use Elastic \Transport \Serializer \TextSerializer ;
27
28
use Elastic \Transport \Serializer \XmlSerializer ;
28
29
use Psr \Http \Message \ResponseInterface ;
29
30
@@ -113,6 +114,10 @@ public function asArray(): array
113
114
$ this ->asArray = CsvSerializer::unserialize ($ this ->asString ());
114
115
return $ this ->asArray ;
115
116
}
117
+ if (strpos ($ contentType , 'text/plain ' ) !== false ) {
118
+ $ this ->asArray = [$ this ->asString ()];
119
+ return $ this ->asArray ;
120
+ }
116
121
throw new UnknownContentTypeException (sprintf (
117
122
"Cannot deserialize the reponse as array with Content-Type: %s " ,
118
123
$ contentType
Original file line number Diff line number Diff line change @@ -200,4 +200,20 @@ public function testAccessAsObject()
200
200
201
201
$ this ->assertEquals ($ array ['foo ' ], $ this ->elasticsearch ->foo );
202
202
}
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
+ }
203
219
}
You can’t perform that action at this time.
0 commit comments