Fix/httpclient bugs#119
Merged
Merged
Conversation
This commit fixes 8 distinct bugs in HttpClient, all of them confirmed by a new test suite (tests/HttpClientTest.php, 37 tests / 72 assertions). Bugs fixed: 1. Base URL was discarded when a relative path was passed to a verb method. Track baseUrl separately and join relative paths to it. 2. Multipart uploads using the documented '@/path' syntax silently sent the literal string. Convert such values to CURLFile and clear any stale Content-Type so cURL can attach the correct multipart boundary. 3. HTTP header injection (CWE-93) was possible because withHeader() accepted CR/LF in names and values. Reject them with InvalidArgumentException. 4. parseResponse() collapsed duplicate response headers, so multiple Set-Cookie headers were lost. Preserve repeats as arrays and use only the final hop's headers when redirects are followed. 5. HttpResponse::header() lookups were case-sensitive, contrary to RFC 7230. Compare with strcasecmp(). 6. queryParams, body and url leaked from one request to the next on the same client. Clear them after each send(); persistent settings (headers, auth, timeouts) deliberately remain. 7. asJson() silently sent an empty body when json_encode() returned false. Throw RuntimeException with json_last_error_msg(). 8. reset() only cleared a subset of fields. Restore every request- shaping property to its initial value (preserving baseUrl). All pre-existing tests pass with no regression.
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.
No description provided.