Skip to content

Commit

Permalink
Include Content-Type: application/json header in all JSON requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixarntz committed Jul 25, 2024
1 parent 47ace82 commit b733c65
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/HTTP/JSON_Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public function __construct( string $url, array $data = array(), array $args = a
// Do not allow passing a body manually, as it will be the JSON-encoded data.
unset( $args['body'] );

// Ensure the Content-Type header is set to application/json, unless otherwise specified.
if ( ! isset( $args['headers'] ) ) {
$args['headers'] = array( 'Content-Type' => 'application/json' );
} elseif ( ! isset( $args['headers']['Content-Type'] ) && ! isset( $args['headers']['content-type'] ) ) {
$args['headers']['Content-Type'] = 'application/json';
}

parent::__construct( $url, $data, $args );
}

Expand Down

0 comments on commit b733c65

Please sign in to comment.