Skip to content

Commit 239f43e

Browse files
authored
Fix issues in HTTP client (#106)
1 parent f9fcb58 commit 239f43e

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/WordPress/AsyncHttp/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function process_queue() {
192192

193193
foreach ( $streams as $k => $stream ) {
194194
$request = $enqueued[ $k ];
195-
$total = $response_headers[ $k ]['headers']['content-length'];
195+
$total = $response_headers[ $k ]['headers']['content-length'] ?? null;
196196
$this->requests[ $request ]->state = RequestInfo::STATE_STREAMING;
197197
$this->requests[ $request ]->stream = stream_monitor_progress(
198198
$stream,

src/WordPress/AsyncHttp/async_http_streams.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,17 @@ function stream_http_prepare_request_bytes( $url ) {
219219
$parts = parse_url( $url );
220220
$host = $parts['host'];
221221
$path = $parts['path'] . ( isset( $parts['query'] ) ? '?' . $parts['query'] : '' );
222-
$request = <<<REQUEST
223-
GET $path HTTP/1.1
224-
Host: $host
225-
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36
226-
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
227-
Accept-Language: en-US,en;q=0.9
228-
Connection: close
229-
REQUEST;
222+
$request_parts = array(
223+
"GET $path HTTP/1.0",
224+
"Host: $host",
225+
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36",
226+
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
227+
"Accept-Language: en-US,en;q=0.9",
228+
"Connection: close"
229+
);
230230

231231
// @TODO: Add support for Accept-Encoding: gzip
232-
233-
return str_replace( "\n", "\r\n", $request ) . "\r\n\r\n";
232+
return implode( "\r\n", $request_parts ) . "\r\n\r\n";
234233
}
235234

236235
/**

0 commit comments

Comments
 (0)