Skip to content

Commit 8316ad3

Browse files
committed
Improve capturing the legacy response
Make sure we don't leave an active output buffer behind when things go south and an exception is thrown. Additionally, don't try to use http_response_code() to figure out the response status code if one has been returned from the $legacyExecutionCallback.
1 parent 6343016 commit 8316ad3

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Integration/LegacyCaptureResponseFactory.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,25 @@ class LegacyCaptureResponseFactory
2828
public static function create($legacyExecutionCallback)
2929
{
3030
ob_start();
31-
$statusCode = call_user_func($legacyExecutionCallback) ?: 200;
31+
try {
32+
$statusCode = call_user_func($legacyExecutionCallback);
33+
$content = ob_get_contents();
34+
} finally {
35+
ob_end_clean();
36+
}
3237

33-
if (function_exists('http_response_code')) {
34-
$statusCode = http_response_code();
38+
if ($statusCode === null) {
39+
if (function_exists('http_response_code')) {
40+
$statusCode = http_response_code();
41+
} else {
42+
$statusCode = 200;
43+
}
3544
}
3645

3746
if (headers_sent()) {
3847
throw new LegacyIntegrationException("It must be possible to caputure the legacy application's output with ob_start(). Headers and/or output must not have been sent to the client.");
3948
}
4049

41-
$content = ob_get_contents();
42-
ob_end_clean();
43-
4450
$headers = headers_list();
4551
header_remove();
4652

0 commit comments

Comments
 (0)