Skip to content

Commit

Permalink
Fix issues in HTTP client (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
MayPaw authored Jun 15, 2024
1 parent f9fcb58 commit 239f43e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/WordPress/AsyncHttp/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function process_queue() {

foreach ( $streams as $k => $stream ) {
$request = $enqueued[ $k ];
$total = $response_headers[ $k ]['headers']['content-length'];
$total = $response_headers[ $k ]['headers']['content-length'] ?? null;
$this->requests[ $request ]->state = RequestInfo::STATE_STREAMING;
$this->requests[ $request ]->stream = stream_monitor_progress(
$stream,
Expand Down
19 changes: 9 additions & 10 deletions src/WordPress/AsyncHttp/async_http_streams.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,17 @@ function stream_http_prepare_request_bytes( $url ) {
$parts = parse_url( $url );
$host = $parts['host'];
$path = $parts['path'] . ( isset( $parts['query'] ) ? '?' . $parts['query'] : '' );
$request = <<<REQUEST
GET $path HTTP/1.1
Host: $host
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
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
Accept-Language: en-US,en;q=0.9
Connection: close
REQUEST;
$request_parts = array(
"GET $path HTTP/1.0",
"Host: $host",
"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",
"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",
"Accept-Language: en-US,en;q=0.9",
"Connection: close"
);

// @TODO: Add support for Accept-Encoding: gzip

return str_replace( "\n", "\r\n", $request ) . "\r\n\r\n";
return implode( "\r\n", $request_parts ) . "\r\n\r\n";
}

/**
Expand Down

0 comments on commit 239f43e

Please sign in to comment.