Class: SlowServer::Client
- Inherits:
-
Object
- Object
- SlowServer::Client
- Defined in:
- lib/slow_server/client.rb
Instance Method Summary collapse
Instance Method Details
#chunk_size ⇒ Object
10 11 12 |
# File 'lib/slow_server/client.rb', line 10 def chunk_size (request.size / config.chunks.to_f).ceil end |
#chunks ⇒ Object
14 15 16 |
# File 'lib/slow_server/client.rb', line 14 def chunks request.scan(/.{1,#{chunk_size}}/m) end |
#config ⇒ Object
6 7 8 |
# File 'lib/slow_server/client.rb', line 6 def config SlowServer.config end |
#request ⇒ Object
18 19 20 |
# File 'lib/slow_server/client.rb', line 18 def request "GET /" end |
#start ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/slow_server/client.rb', line 22 def start TCPSocket.open("127.0.0.1", 4000) do |socket| STDERR.puts "Waiting for #{config.response_delay} seconds" sleep config.response_delay chunks.each do |chunk| STDERR.puts "Sending #{chunk_size} bytes" socket.print chunk STDERR.puts "Waiting for #{config.chunk_delay} seconds" sleep config.chunk_delay end socket.print("\r\n\r\n") response = socket.read headers,body = response.split("\r\n\r\n", 2) STDERR.puts "\n" print body end end |