Repository navigation
Conversation
With CURLOPT_HEADER curl returns the interim "100 Continue" response in front of the final one. For a request body over 1 MB libcurl sends "Expect: 100-continue" on its own, so parseResponse() returned status 100 with no headers and the body "HTTP/1.1 200 OK". Skip interim 1xx responses (except 101) before parsing, and keep CRLF sequences inside the body instead of truncating it at the first one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Elastic\Transport\Client\Curlruns curl withCURLOPT_HEADER => true, so curl returns every response block it received. For a request body over 1 MB libcurl addsExpect: 100-continueon its own, the server answersHTTP/1.1 100 Continueand then the real response.parseResponse()reads the first status line and the first header block, so it returns status 100 with no headers and the bodyHTTP/1.1 200 OK. In elasticsearch-php this surfaces asUnknownContentTypeException: No Content-Type specified in the response, becauseElasticsearch::setResponse()only throws for 4xx/5xx and only runs the product check for 2xx.Changes in
src/Client/Curl.php:101 Switching Protocols, which is final) before parsing.\r\nwas truncated at the first one.Tests
New
tests/Client/CurlInterimResponseTest.phpwith a small raw-socket server (interim_server.php), since the built-in PHP server cannot send a100 Continue:Expect: 100-continueheader, final 200 with headers and body expectedExpectitself)All three fail on
main(PHP 8.1, libcurl):Failed asserting that 100 is identical to 200.and, for the body test,-'first\r\nsecond' +'first'. They pass with the change. Full suite 135 tests OK and PHPStan clean.Relation to ruflin/Elastica
Expectheader when the Curl client is in use. It stays valid for users on olderelastic/transportversions.elastic/transport(viaelasticsearch/elasticsearch) and drop the workaround. The two are compatible, so no ordering is required.elastic/transport.Not covered: proxy
CONNECTresponses and redirect chains (CURLOPT_FOLLOWLOCATION) still produce the first block, as before.