Skip to content

Commit c7ed61b

Browse files
committed
AsyncHttp\\Client: Use false, not null to indicate missing response headers
For transfer-encoding: chunked, the content-length header was missing. A confusion around checking for false vs null made the client assume no response body is coming back and close the connection prematurely.
1 parent b2c8d38 commit c7ed61b

File tree

3 files changed

+4
-16
lines changed

3 files changed

+4
-16
lines changed

http_proxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function get_target_url($server_data=null) {
5757
switch ( $client->get_event() ) {
5858
case Client::EVENT_GOT_HEADERS:
5959
http_response_code($request->response->status_code);
60-
foreach ( $request->response->get_headers() as $name => $value ) {
60+
foreach ( $request->response->headers as $name => $value ) {
6161
if(
6262
$name === 'transfer-encoding' ||
6363
$name === 'set-cookie' ||

src/WordPress/AsyncHttp/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ private function receive_response_headers( $requests ) {
590590
$response->protocol = $parsed['status']['protocol'];
591591

592592
$total = $request->response->get_header( 'content-length' );
593-
if ( $total !== null ) {
593+
if ( false !== $total ) {
594594
$response->total_bytes = (int) $total;
595595
}
596596

@@ -660,7 +660,7 @@ private function handle_redirects( $requests ) {
660660
}
661661

662662
$location = $response->get_header( 'location' );
663-
if ( $location === null ) {
663+
if ( false === $location ) {
664664
continue;
665665
}
666666

src/WordPress/AsyncHttp/Response.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,7 @@ public function __construct( Request $request ) {
1818
}
1919

2020
public function get_header( $name ) {
21-
$headers = $this->get_headers();
22-
if ( false === $headers ) {
23-
return false;
24-
}
25-
return $headers[ strtolower( $name ) ] ?? false;
26-
}
27-
28-
public function get_headers() {
29-
if ( ! $this->headers ) {
30-
return false;
31-
}
32-
33-
return $this->headers;
21+
return $this->headers[ strtolower( $name ) ] ?? false;
3422
}
3523

3624
}

0 commit comments

Comments
 (0)