Skip to content

Commit

Permalink
Send no content-type header if there are no body
Browse files Browse the repository at this point in the history
  • Loading branch information
kkopachev committed Jun 29, 2022
1 parent a69131b commit 633a3cc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Service/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function call($name, $arguments, $expectedClass = null)
$request = new Request(
$method['httpMethod'],
$url,
['content-type' => 'application/json'],
$postBody ? ['content-type' => 'application/json'] : [],
$postBody ? json_encode($postBody) : ''
);

Expand Down
33 changes: 28 additions & 5 deletions tests/Google/Service/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,29 @@ public function testCall()
$request = $resource->call("testMethod", [[]]);
$this->assertEquals("https://test.example.com/method/path", (string) $request->getUri());
$this->assertEquals("POST", $request->getMethod());
$this->assertFalse($request->hasHeader('Content-Type'));
}

public function testCallWithPostBody()
{
$resource = new GoogleResource(
$this->service,
"test",
"testResource",
["methods" =>
[
"testMethod" => [
"parameters" => [],
"path" => "method/path",
"httpMethod" => "GET",
]
]
]
);
$request = $resource->call("testMethod", array(array('postBody' => ['foo' => 'bar'])));
$this->assertEquals("https://test.example.com/method/path", (string) $request->getUri());
$this->assertEquals("GET", $request->getMethod());
$this->assertTrue($request->hasHeader('Content-Type'));
}

public function testCallServiceDefinedRoot()
Expand All @@ -130,11 +153,11 @@ public function testCallServiceDefinedRoot()
}

/**
* Some Google Service (Google\Service\Directory\Resource\Channels and
* Google\Service\Reports\Resource\Channels) use a different servicePath value
* that should override the default servicePath value, it's represented by a /
* before the resource path. All other Services have no / before the path
*/
* Some Google Service (Google\Service\Directory\Resource\Channels and
* Google\Service\Reports\Resource\Channels) use a different servicePath value
* that should override the default servicePath value, it's represented by a /
* before the resource path. All other Services have no / before the path
*/
public function testCreateRequestUriForASelfDefinedServicePath()
{
$this->service->servicePath = '/admin/directory/v1/';
Expand Down

0 comments on commit 633a3cc

Please sign in to comment.