-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from clue-labs/write-chunk-size
Add optional $writeChunkSize parameter for max number of bytes to write
- Loading branch information
Showing
3 changed files
with
129 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace React\Tests\Stream; | ||
|
||
use React\Stream\DuplexResourceStream; | ||
use React\EventLoop\Factory; | ||
use React\Stream\WritableResourceStream; | ||
|
||
/** | ||
* @group internet | ||
*/ | ||
class FunctionalInternetTest extends TestCase | ||
{ | ||
public function testUploadKilobytePlain() | ||
{ | ||
$size = 1000; | ||
$stream = stream_socket_client('tcp://httpbin.org:80'); | ||
|
||
$loop = Factory::create(); | ||
$stream = new DuplexResourceStream($stream, $loop); | ||
|
||
$buffer = ''; | ||
$stream->on('data', function ($chunk) use (&$buffer) { | ||
$buffer .= $chunk; | ||
}); | ||
|
||
$stream->on('error', $this->expectCallableNever()); | ||
|
||
$stream->write("POST /post HTTP/1.0\r\nHost: httpbin.org\r\nContent-Length: $size\r\n\r\n" . str_repeat('.', $size)); | ||
|
||
$loop->run(); | ||
|
||
$this->assertNotEquals('', $buffer); | ||
} | ||
|
||
public function testUploadBiggerBlockPlain() | ||
{ | ||
$size = 1000 * 30; | ||
$stream = stream_socket_client('tcp://httpbin.org:80'); | ||
|
||
$loop = Factory::create(); | ||
$stream = new DuplexResourceStream($stream, $loop); | ||
|
||
$buffer = ''; | ||
$stream->on('data', function ($chunk) use (&$buffer) { | ||
$buffer .= $chunk; | ||
}); | ||
|
||
$stream->on('error', $this->expectCallableNever()); | ||
|
||
$stream->write("POST /post HTTP/1.0\r\nHost: httpbin.org\r\nContent-Length: $size\r\n\r\n" . str_repeat('.', $size)); | ||
|
||
$loop->run(); | ||
|
||
$this->assertNotEquals('', $buffer); | ||
} | ||
|
||
public function testUploadKilobyteSecure() | ||
{ | ||
$size = 1000; | ||
$stream = stream_socket_client('tls://httpbin.org:443'); | ||
|
||
$loop = Factory::create(); | ||
$stream = new DuplexResourceStream($stream, $loop); | ||
|
||
$buffer = ''; | ||
$stream->on('data', function ($chunk) use (&$buffer) { | ||
$buffer .= $chunk; | ||
}); | ||
|
||
$stream->on('error', $this->expectCallableNever()); | ||
|
||
$stream->write("POST /post HTTP/1.0\r\nHost: httpbin.org\r\nContent-Length: $size\r\n\r\n" . str_repeat('.', $size)); | ||
|
||
$loop->run(); | ||
|
||
$this->assertNotEquals('', $buffer); | ||
} | ||
|
||
public function testUploadBiggerBlockSecureRequiresSmallerChunkSize() | ||
{ | ||
$size = 1000 * 30000; | ||
$stream = stream_socket_client('tls://httpbin.org:443'); | ||
|
||
$loop = Factory::create(); | ||
$stream = new DuplexResourceStream( | ||
$stream, | ||
$loop, | ||
null, | ||
new WritableResourceStream($stream, $loop, null, 8192) | ||
); | ||
|
||
$buffer = ''; | ||
$stream->on('data', function ($chunk) use (&$buffer) { | ||
$buffer .= $chunk; | ||
}); | ||
|
||
$stream->on('error', $this->expectCallableNever()); | ||
|
||
$stream->write("POST /post HTTP/1.0\r\nHost: httpbin.org\r\nContent-Length: $size\r\n\r\n" . str_repeat('.', $size)); | ||
|
||
$loop->run(); | ||
|
||
$this->assertNotEquals('', $buffer); | ||
} | ||
} |