Skip to content

Curl client parses the "100 Continue" interim response as the final response (requests over 1 MB fail with UnknownContentTypeException) #2321

Open

Description

@andrii-pukhalevych

Summary

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

use Elastic\Transport\TransportBuilder;
use Nyholm\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 = new Request('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 1 MB is parsed correctly, because curl does not add the Expect header below that size. curl -v shows what the client receives:

< HTTP/1.1 100 Continue
<   
< HTTP/1.1 200 OK
< 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 0 as the status line and stops at the first empty line, which is the end of the 100 Continue
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.

Activity

  1. added 2 commits that reference this issue on Oct 22, 2026
    96fb4f9
    495d4f1
  2. andrii-pukhalevych commented on Oct 27, 2026

    @andrii-pukhalevych
    Author

    @ruflin please check it. Its important issue that blocks normal usage of this library

  3. ruflin commented on Oct 28, 2026

    @ruflin
    Owner

    @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?

  4. andrii-pukhalevych commented on Oct 28, 2026

    @andrii-pukhalevych
    Author

    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.

  5. ruflin commented on Oct 28, 2026

    @ruflin
    Owner

    I opened a draft PR with the root-cause fix in the transport library: elastic/elastic-transport-php#48

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions