Skip to content

Commit a2002d5

Browse files
Leverage php-http/discovery v1.15 and decouple from guzzlehttp/psr7
1 parent 377e044 commit a2002d5

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@
2424
"ext-json": "*",
2525
"ext-mbstring": "*",
2626
"guzzlehttp/promises": "^1.4",
27-
"guzzlehttp/psr7": "^1.8.4|^2.1.1",
2827
"jean85/pretty-package-versions": "^1.5|^2.0.4",
29-
"php-http/async-client-implementation": "^1.0",
28+
"php-http/async-client-implementation": "^1.1|^2.0",
3029
"php-http/client-common": "^1.5|^2.0",
31-
"php-http/discovery": "^1.11",
30+
"php-http/discovery": "^1.15",
3231
"php-http/httplug": "^1.1|^2.0",
3332
"php-http/message": "^1.5",
3433
"psr/http-factory": "^1.0",
35-
"psr/http-message-implementation": "^1.0",
34+
"psr/http-factory-implementation": "^1.0",
3635
"psr/log": "^1.0|^2.0|^3.0",
3736
"symfony/options-resolver": "^3.4.43|^4.4.30|^5.0.11|^6.0",
3837
"symfony/polyfill-php80": "^1.17"
3938
},
4039
"require-dev": {
4140
"friendsofphp/php-cs-fixer": "^2.19|3.4.*",
41+
"guzzlehttp/psr7": "^1.8.4|^2.1.1",
4242
"http-interop/http-factory-guzzle": "^1.0",
4343
"monolog/monolog": "^1.6|^2.0|^3.0",
4444
"nikic/php-parser": "^4.10.3",

src/Integration/RequestFetcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Sentry\Integration;
66

7-
use GuzzleHttp\Psr7\ServerRequest;
7+
use Http\Discovery\Psr17Factory;
88
use Psr\Http\Message\ServerRequestInterface;
99

1010
/**
@@ -22,6 +22,6 @@ public function fetchRequest(): ?ServerRequestInterface
2222
return null;
2323
}
2424

25-
return ServerRequest::fromGlobals();
25+
return (new Psr17Factory())->createServerRequestFromGlobals();
2626
}
2727
}

src/Integration/RequestIntegration.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Sentry\Integration;
66

7-
use GuzzleHttp\Psr7\Utils;
87
use Psr\Http\Message\ServerRequestInterface;
98
use Psr\Http\Message\UploadedFileInterface;
109
use Sentry\Event;
@@ -50,7 +49,7 @@ final class RequestIntegration implements IntegrationInterface
5049
'never' => 0,
5150
'small' => self::REQUEST_BODY_SMALL_MAX_CONTENT_LENGTH,
5251
'medium' => self::REQUEST_BODY_MEDIUM_MAX_CONTENT_LENGTH,
53-
'always' => -1,
52+
'always' => \PHP_INT_MAX,
5453
];
5554

5655
/**
@@ -224,7 +223,19 @@ private function captureRequestBody(Options $options, ServerRequestInterface $re
224223
return $requestData;
225224
}
226225

227-
$requestBody = Utils::copyToString($request->getBody(), self::MAX_REQUEST_BODY_SIZE_OPTION_TO_MAX_LENGTH_MAP[$maxRequestBodySize]);
226+
$requestBody = '';
227+
$maxLength = self::MAX_REQUEST_BODY_SIZE_OPTION_TO_MAX_LENGTH_MAP[$maxRequestBodySize];
228+
229+
if (0 < $maxLength) {
230+
$stream = $request->getBody();
231+
while (0 < $maxLength && !$stream->eof()) {
232+
if ('' === $buffer = $stream->read(min($maxLength, self::REQUEST_BODY_MEDIUM_MAX_CONTENT_LENGTH))) {
233+
break;
234+
}
235+
$requestBody .= $buffer;
236+
$maxLength -= \strlen($buffer);
237+
}
238+
}
228239

229240
if ('application/json' === $request->getHeaderLine('Content-Type')) {
230241
try {

0 commit comments

Comments
 (0)