You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Curl client parses the "100 Continue" interim response as the final response (requests over 1 MB fail with UnknownContentTypeException) #2321
Elastic\Transport\Client\Curl runs curl with CURLOPT_HEADER => true and parseResponse() reads the first status line and the first header block of what curl returns. For a request body over 1 MB, libcurl adds Expect: 100-continue on its own; Elasticsearch answers HTTP/1.1 100 Continue and then the real response. The parsed response is then status 100 with no headers and the body HTTP/1.1 200 OK.
Nothing downstream catches a 1xx: in elasticsearch-php Elasticsearch::setResponse() throws only for 4xx/5xx and runs the product check only for 2xx, so the failure surfaces as
Elastic\Transport\Exception\UnknownContentTypeException: No Content-Type specified in the response
from Elasticsearch::asArray(). In practice every bulk request over 1 MB fails this way when the Curl client is in use (no other PSR-18 client installed).
Environment
elastic/transport v9.0.1, elasticsearch/elasticsearch v9.5.0 (also via ruflin/elastica 9.0.0)
PHP 8.3.33, libcurl 8.5.0
Elasticsearch 7.16.2
Steps to reproduce
useElastic\Transport\TransportBuilder;
useNyholm\Psr7\Request;
$transport = TransportBuilder::create()->setHosts(['http://localhost:9200'])->build();
$body = '{"size":0,' . str_repeat('', 1200000) . '"query":{"match_all":{}}}'; // 1.2 MB of valid JSON$request = newRequest('POST', '/my-index/_search', ['Content-Type' => 'application/json'], $body);
$response = $transport->sendRequest($request);
var_dump($response->getStatusCode(), $response->getHeaderLine('Content-Type'), substr((string)$response->getBody(), 0, 15));
// int(100) string(0) "" string(15) "HTTP/1.1 200 OK"$response = $transport->sendRequest($request->withHeader('Expect', ''));
var_dump($response->getStatusCode(), $response->getHeaderLine('Content-Type'));
// int(200) string(31) "application/json; charset=UTF-8"
The same request with a body under 1MB is parsed correctly, because curl does not add the Expect header below that size. curl -v shows what the client receives:
< HTTP/1.1100Continue
<
< HTTP/1.1200OK
< content-type: application/json; charset=UTF-8
...
Expected
Status 200 with the headers and body of the final response, whatever the body size.
Cause
Curl::parseResponse() (src/Client/Curl.php) splits the raw response on CRLF, takes line 0as the status line and stops at the first empty line, which is the end of the 100Continue
block. The final status line and headers that follow are never looked at.
Suggested fix
Either skip interim responses in parseResponse(): when the parsed status code is 1xx, drop everything up to and including the blank line and parse again; or keep curl from asking
for them by sending Expect: (empty) in CURLOPT_HTTPHEADER unless the request sets the header itself.
Workaround
$transport->setHeader('Expect', ''), which makes curl send the body without the expectation.
@andrii-pukhalevych Thanks for the report and also directly the pull request. The part I'm hesitant about is that I think this should be fixed upstream in php-elasticsearch directly as Elastica relies on. What do you think?
I fully agree. Strange that nobody reported it earlier. But actually it happens on large data so developers just start using another wraps instead of reporting.
Curl::parseResponse() now skips interim 1xx responses (100 Continue) and returns the final response. It also stops truncating bodies that contain CRLF. The regression tests fail without the change (status 100 instead of 200, also for a 1.2 MB body with no explicit Expect header) and pass with it.
Once a new elastic/transport release is out, Elastica can raise its minimum version. Until then #2322 still helps users on older transport versions, and the two changes do not conflict.
Activity
fix: disable Expect: 100-continue for the Curl client of elastic/tran…
fix: disable Expect: 100-continue for the Curl client of elastic/tran…
andrii-pukhalevych commentedon Oct 27, 2026
@ruflin please check it. Its important issue that blocks normal usage of this library
ruflin commentedon Oct 28, 2026
@andrii-pukhalevych Thanks for the report and also directly the pull request. The part I'm hesitant about is that I think this should be fixed upstream in php-elasticsearch directly as Elastica relies on. What do you think?
andrii-pukhalevych commentedon Oct 28, 2026
I fully agree. Strange that nobody reported it earlier. But actually it happens on large data so developers just start using another wraps instead of reporting.
ruflin commentedon Oct 28, 2026
I opened a draft PR with the root-cause fix in the transport library: elastic/elastic-transport-php#48
Curl::parseResponse()now skips interim1xxresponses (100 Continue) and returns the final response. It also stops truncating bodies that contain CRLF. The regression tests fail without the change (status100instead of200, also for a 1.2 MB body with no explicitExpectheader) and pass with it.Once a new
elastic/transportrelease is out, Elastica can raise its minimum version. Until then #2322 still helps users on older transport versions, and the two changes do not conflict.