Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 76b7a0a

Browse filesBrowse files
[HttpClient] Fix retrying requests with Psr18Client and NTLM connections
1 parent 7ce6078 commit 76b7a0a
Copy full SHA for 76b7a0a

File tree

Expand file treeCollapse file tree

3 files changed

+62
-20
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+62
-20
lines changed

‎CurlHttpClient.php

Copy file name to clipboardExpand all lines: CurlHttpClient.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ public function request(string $method, string $url, array $options = []): Respo
236236
}
237237

238238
if (!\is_string($body)) {
239+
if (isset($options['auth_ntlm'])) {
240+
$curlopts[\CURLOPT_FORBID_REUSE] = true; // Reusing NTLM connections requires seeking capability, which only string bodies support
241+
}
242+
239243
if (\is_resource($body)) {
240244
$curlopts[\CURLOPT_INFILE] = $body;
241245
} else {

‎HttplugClient.php

Copy file name to clipboardExpand all lines: HttplugClient.php
+29-10Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,23 +224,42 @@ private function sendPsr7Request(RequestInterface $request, ?bool $buffer = null
224224
{
225225
try {
226226
$body = $request->getBody();
227+
$headers = $request->getHeaders();
227228

228-
if ($body->isSeekable()) {
229-
try {
230-
$body->seek(0);
231-
} catch (\RuntimeException) {
232-
// ignore
233-
}
229+
$size = $request->getHeader('content-length')[0] ?? -1;
230+
if (0 > $size && 0 <= $size = $body->getSize() ?? -1) {
231+
$headers['Content-Length'] = [$size];
234232
}
235233

236-
$headers = $request->getHeaders();
237-
if (!$request->hasHeader('content-length') && 0 <= $size = $body->getSize() ?? -1) {
238-
$headers['Content-Length'] = [$size];
234+
if (0 <= $size && $size < 1 << 21) {
235+
if ($body->isSeekable()) {
236+
try {
237+
$body->seek(0);
238+
} catch (\RuntimeException) {
239+
// ignore
240+
}
241+
}
242+
243+
$body = $body->getContents();
244+
} else {
245+
$body = static function (int $size) use ($body) {
246+
if ($body->isSeekable()) {
247+
try {
248+
$body->seek(0);
249+
} catch (\RuntimeException) {
250+
// ignore
251+
}
252+
}
253+
254+
while (!$body->eof()) {
255+
yield $body->read($size);
256+
}
257+
};
239258
}
240259

241260
$options = [
242261
'headers' => $headers,
243-
'body' => static fn (int $size) => $body->read($size),
262+
'body' => $body,
244263
'buffer' => $buffer,
245264
];
246265

‎Psr18Client.php

Copy file name to clipboardExpand all lines: Psr18Client.php
+29-10Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,42 @@ public function sendRequest(RequestInterface $request): ResponseInterface
8888
{
8989
try {
9090
$body = $request->getBody();
91+
$headers = $request->getHeaders();
9192

92-
if ($body->isSeekable()) {
93-
try {
94-
$body->seek(0);
95-
} catch (\RuntimeException) {
96-
// ignore
97-
}
93+
$size = $request->getHeader('content-length')[0] ?? -1;
94+
if (0 > $size && 0 <= $size = $body->getSize() ?? -1) {
95+
$headers['Content-Length'] = [$size];
9896
}
9997

100-
$headers = $request->getHeaders();
101-
if (!$request->hasHeader('content-length') && 0 <= $size = $body->getSize() ?? -1) {
102-
$headers['Content-Length'] = [$size];
98+
if (0 <= $size && $size < 1 << 21) {
99+
if ($body->isSeekable()) {
100+
try {
101+
$body->seek(0);
102+
} catch (\RuntimeException) {
103+
// ignore
104+
}
105+
}
106+
107+
$body = $body->getContents();
108+
} else {
109+
$body = static function (int $size) use ($body) {
110+
if ($body->isSeekable()) {
111+
try {
112+
$body->seek(0);
113+
} catch (\RuntimeException) {
114+
// ignore
115+
}
116+
}
117+
118+
while (!$body->eof()) {
119+
yield $body->read($size);
120+
}
121+
};
103122
}
104123

105124
$options = [
106125
'headers' => $headers,
107-
'body' => static fn (int $size) => $body->read($size),
126+
'body' => $body,
108127
];
109128

110129
if ('1.0' === $request->getProtocolVersion()) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.