Skip to content

Commit def86e5

Browse files
Fix issue when http headers are already present (jsonrainbow#843)
This fixes a regression introduced in jsonrainbow#841 If a process/request runs: - file_get_contents on an HTTP URL. - then a json-schema validation using a file://... URL as schema (not all schema are remotely loaded) - and `http_get_last_response_headers()` is available Then you end up with: - file_get_contents on the URL fills up the headers of that request - json-schema validation loads the schema file but using file:// there are no headers, and it seems like file_get_contents does not clear previous headers itself - http_get_last_response_headers() then returns the headers of the previous request - and then `$this->fetchContentType()` will fail unless the response headers were of the correct `application/schema+json` mime type (which is very unlikely). So this PR clears the headers before we fetch the schema, to make sure we have a clean slate. I'll probably report this to PHP as well because IMO it is a bit surprising. --------- Co-authored-by: Danny van der Sluijs <[email protected]>
1 parent b5ab21e commit def86e5

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
### Fixed
10+
- Fix issue when http headers are already present ([#843](https://github.com/jsonrainbow/json-schema/pull/843))
911

1012
## [6.5.1] - 2025-08-29
1113
### Changed

src/JsonSchema/Uri/Retrievers/FileGetContents.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class FileGetContents extends AbstractRetriever
2929
*/
3030
public function retrieve($uri)
3131
{
32+
if (function_exists('http_clear_last_response_headers')) {
33+
http_clear_last_response_headers();
34+
}
35+
3236
$errorMessage = null;
3337
set_error_handler(function ($errno, $errstr) use (&$errorMessage) {
3438
$errorMessage = $errstr;

0 commit comments

Comments
 (0)