Skip to content

Commit

Permalink
Fix http-client content_type method (#409)
Browse files Browse the repository at this point in the history
Using content_type() multiples times (as with as_form(), since the object is created with default as_json()) results in a header array value which trigger an "array to string conversion" error in Requests
  • Loading branch information
nlemoine committed Jul 26, 2023
1 parent ac9159d commit c352679
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mantle/http-client/class-pending-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function body_format( string $format ) {
* @return static
*/
public function content_type( string $content_type ) {
return $this->with_headers( [ 'Content-Type' => $content_type ] );
return $this->with_header( 'Content-Type', $content_type, true );
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/http-client/test-http-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,11 @@ public function test_conditionable_unless_request() {

$this->assertEquals( 'Bar', $request->header( 'X-Foo' ) );
}

public function test_headers_as_form() {
$request = $this->http_factory
->as_form();

$this->assertEquals( 'application/x-www-form-urlencoded', $request->header( 'Content-Type' ) );
}
}

0 comments on commit c352679

Please sign in to comment.