Skip to content

Commit

Permalink
Properly cleanup server headers during testing (#529)
Browse files Browse the repository at this point in the history
* Cleanup any HTTP header set as a server variable

* One more adjustment
  • Loading branch information
srtfisher authored Apr 15, 2024
1 parent 5a0f8f3 commit 35f9a50
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v1.0.3 - 2024-04-15

### Fixed

- Proper unset server headers when testing.

## v1.0.2 - 2024-04-15

### Added
Expand Down
15 changes: 15 additions & 0 deletions src/mantle/testing/class-pending-testable-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,21 @@ protected function reset_request_state(): void {

$this->rest_api_response = null;

// Remove all HTTP_* headers from $_SERVER.
foreach ( $_SERVER as $key => $value ) {
if ( str_starts_with( $key, 'HTTP_' ) && 'HTTP_HOST' !== $key ) {
unset( $_SERVER[ $key ] );
}

if ( isset( $_SERVER['CONTENT_TYPE'] ) ) {
unset( $_SERVER['CONTENT_TYPE'] );
}

if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
unset( $_SERVER['REMOTE_ADDR'] );
}
}

// phpcs:enable
}

Expand Down

0 comments on commit 35f9a50

Please sign in to comment.