8000 bug #34669 [HttpClient] turn exception into log when the request has … · symfony/symfony@396da37 · GitHub
[go: up one dir, main page]

Skip to content

Commit 396da37

Browse files
bug #34669 [HttpClient] turn exception into log when the request has 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
2 parents 3f13e8e + 4c671a4 commit 396da37

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Symfony/Component/HttpClient/Response/NativeResponse.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,18 @@ public function __destruct()
109109

110110
private function open(): void
111111
{
112-
set_error_handler(function ($type, $msg) { throw new TransportException($msg); });
112+
$url = $this->url;
113+
114+
set_error_handler(function ($type, $msg) use (&$url) {
115+
if (E_NOTICE !== $type || 'fopen(): Content-type not specified assuming application/x-www-form-urlencoded' !== $msg) {
116+
throw new TransportException($msg);
117+
}
118+
119+
$this->logger && $this->logger->info(sprintf('%s for "%s".', $msg, $url ?? $this->url));
120+
});
113121

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

118125
while (true) {
119126
$context = stream_context_get_options($this->context);

0 commit comments

Comments
 (0)
0