Skip to content

Commit

Permalink
Merge pull request #82 from aaa2000/fix-curlformatter-useragent
Browse files Browse the repository at this point in the history
Fix curl command of CurlFormatter when there is an user-agent header
  • Loading branch information
Nyholm committed Jun 28, 2017
2 parents aa70fb8 + 05aea15 commit e033e4f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

- CookieUtil::parseDate to create a date from cookie date string

### Fixed

- Fix curl command of CurlFormatter when there is an user-agent header

## 1.5.0 - 2017-02-14

### Added
Expand Down
14 changes: 14 additions & 0 deletions spec/Formatter/CurlCommandFormatterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,18 @@ function it_does_nothing_for_response(ResponseInterface $response)
{
$this->formatResponse($response)->shouldReturn('');
}

function it_formats_the_request_with_user_agent(RequestInterface $request, UriInterface $uri, StreamInterface $body)
{
$request->getUri()->willReturn($uri);
$request->getBody()->willReturn($body);

$uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar');
$request->getMethod()->willReturn('GET');
$request->getProtocolVersion()->willReturn('1.1');
$uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar');
$request->getHeaders()->willReturn(['user-agent'=>['foobar-browser']]);

$this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' -A 'foobar-browser'");
}
}
2 changes: 1 addition & 1 deletion src/Formatter/CurlCommandFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private function getHeadersAsCommandOptions(RequestInterface $request)
}

if ('user-agent' === strtolower($name)) {
$command .= sprintf('-A %s', escapeshellarg($values[0]));
$command .= sprintf(' -A %s', escapeshellarg($values[0]));
continue;
}

Expand Down

0 comments on commit e033e4f

Please sign in to comment.