Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not receive a response until a timeout is reached #2

Closed
M0nik opened this issue May 10, 2020 · 6 comments
Closed

Not receive a response until a timeout is reached #2

M0nik opened this issue May 10, 2020 · 6 comments

Comments

@M0nik
Copy link

M0nik commented May 10, 2020

Hello!
When I make a request, I don't receive a response until a timeout is reached. In Request.php, function checkComplete waits the connection to be closed if empty Content-Length. Why? For responses with a code of 200 and not empty response body everything works correctly, but if the answer is 401 or 201 with empty body, we are waiting for the closing.

@walkor
Copy link
Owner

walkor commented May 11, 2020

Please show your codes or give an example to reproduce the issue.

For response messages, whether or not a message-body is included with
a message is dependent on both the request method and the response
status code (section 6.1.1). All responses to the HEAD request method
MUST NOT include a message-body, even though the presence of entity-
header fields might lead one to believe they do. All 1xx
(informational), 204 (no content), and 304 (not modified) responses
MUST NOT include a message-body. All other responses do include a
message-body, although it MAY be of zero length.

https://tools.ietf.org/html/rfc2616#section-4.3

According to the RFC specification, 201 and 401 do include a
message-body although it MAY be of zero length. So if the status codes is 201 or 401 the head must include a Message Length field which can be Transfer-Encoding or Content-Length or multipart/byteranges or By the server closing the connection to tell the length of message-body.

@M0nik
Copy link
Author

M0nik commented May 11, 2020

Example:

<?php

require __DIR__ . '/vendor/autoload.php';

use Workerman\Http\Client;
use Workerman\Worker;

$worker = new Worker();
$worker->count = 1;

$worker->onWorkerStart = function () {
	$http_async_client = new Client( [
		'connect_timeout' => 10,
		'timeout'         => 10,
	] );
	$start_time = microtime( true );
	$http_async_client->get(
		"https://apip.orangedata.ru:2443/api/v2/devices/status/12345678910/Main",
		function () use ( $start_time ) {
			echo 'Elapsed time ' . round( microtime( true ) - $start_time, 2 ). ' sec';
		}
	);
};

Worker::runAll();

Output:
Elapsed time 10.12 sec

@walkor walkor closed this as completed in 024e19c May 11, 2020
@walkor
Copy link
Owner

walkor commented May 11, 2020

Please upgrade to v0.1.6.

@M0nik
Copy link
Author

M0nik commented May 11, 2020

Great, it works!
Elapsed time 0.24 sec

There is another issue. In the current implementation, it is not possible to set SSL certificates.
Now I've extended ConnectionPool and Client class and work as follows:

protected function create($address, $ssl = false)
{
    $context = [];
    if ( !empty( $this->_option['context'] ) ) {
        $context = $this->_option['context'];
    }
    $connection = new AsyncTcpConnection($address, $context);
    ...
}
$custom_http_client = new Client( [
  'connect_timeout' => 10,
  'timeout'         => 10,
  'context'         => [
    'ssl' => [
      'local_cert' => $this->client_crt_path,
      'local_pk'   => $this->client_key_path,
     ],
   ],
] );

What about native support?

@walkor
Copy link
Owner

walkor commented May 11, 2020

Please upgrade again.

@M0nik
Copy link
Author

M0nik commented May 11, 2020

Awesome! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants