forked from reactphp/http
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close inactive connections and requests
This new middleware introduces a timeout of closing inactive connections between requests after a configured amount of seconds. This builds on top of reactphp#405 and partially on reactphp#422
- Loading branch information
1 parent
00f3590
commit 25f7136
Showing
8 changed files
with
253 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace React\Http\Middleware; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use React\Http\Io\HttpBodyStream; | ||
use React\Http\Io\PauseBufferStream; | ||
use React\Promise; | ||
use React\Promise\PromiseInterface; | ||
use React\Promise\Deferred; | ||
use React\Stream\ReadableStreamInterface; | ||
|
||
/** | ||
* Closes any inactive connection after the specified amount of seconds since last activity. | ||
* | ||
* This allows you to set an alternative timeout to the default one minute (60 seconds). For example | ||
* thirteen and a half seconds: | ||
* | ||
* ```php | ||
* $http = new React\Http\HttpServer( | ||
* new React\Http\Middleware\InactiveConnectionTimeoutMiddleware(13.5), | ||
* $handler | ||
* ); | ||
* | ||
* > Internally, this class is used as a "value object" to override the default timeout of one minute. | ||
* As such it doesn't have any behavior internally, that is all in the internal "StreamingServer". | ||
*/ | ||
final class InactiveConnectionTimeoutMiddleware | ||
{ | ||
/** | ||
* @internal | ||
*/ | ||
const DEFAULT_TIMEOUT = 60; | ||
|
||
/** | ||
* @var float | ||
*/ | ||
private $timeout; | ||
|
||
/** | ||
* @param float $timeout | ||
*/ | ||
public function __construct($timeout = self::DEFAULT_TIMEOUT) | ||
{ | ||
$this->timeout = $timeout; | ||
} | ||
|
||
public function __invoke(ServerRequestInterface $request, $next) | ||
{ | ||
return $next($request); | ||
} | ||
|
||
/** | ||
* @return float | ||
* @internal | ||
*/ | ||
public function getTimeout() | ||
{ | ||
return $this->timeout; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.