Skip to content

Commit

Permalink
bug #34669 [HttpClient] turn exception into log when the request has …
Browse files Browse the repository at this point in the history
…no content-type (nicolas-grekas)

This PR was merged into the 4.3 branch.

Discussion
----------

[HttpClient] turn exception into log when the request has no content-type

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Spotted while merging a PR with ext-curl disabled:

```
  [Symfony\Component\HttpClient\Exception\TransportException]
  fopen(): Content-type not specified assuming application/x-www-form-urlencoded
```

This is now a log.

Commits
-------

4c671a4 [HttpClient] turn exception into log when the request has no content-type
  • Loading branch information
nicolas-grekas committed Nov 28, 2019
2 parents 3f13e8e + 4c671a4 commit 396da37
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Symfony/Component/HttpClient/Response/NativeResponse.php
Expand Up @@ -109,11 +109,18 @@ public function __destruct()

private function open(): void
{
set_error_handler(function ($type, $msg) { throw new TransportException($msg); });
$url = $this->url;

set_error_handler(function ($type, $msg) use (&$url) {
if (E_NOTICE !== $type || 'fopen(): Content-type not specified assuming application/x-www-form-urlencoded' !== $msg) {
throw new TransportException($msg);
}

$this->logger && $this->logger->info(sprintf('%s for "%s".', $msg, $url ?? $this->url));
});

try {
$this->info['start_time'] = microtime(true);
$url = $this->url;

while (true) {
$context = stream_context_get_options($this->context);
Expand Down

0 comments on commit 396da37

Please sign in to comment.