Last active
October 11, 2017 04:54
-
-
Save Aupajo/aeba7dc6ce0aed678c989d39c75a7740 to your computer and use it in GitHub Desktop.
Rack timings
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
require 'socket' | |
socket = TCPSocket.open('localhost', 9292) | |
puts "Sending headers at #{Time.now.strftime('%T.%L')}" | |
socket.puts <<~REQUEST | |
POST / HTTP/1.1\r | |
Host: localhost:9292\r | |
Accept: */*\r | |
Content-Length: 3\r | |
Content-Type: application/x-www-form-urlencoded\r | |
\r | |
REQUEST | |
sleep 1 | |
puts "Sending at #{Time.now.strftime('%T.%L')}" | |
socket.puts "." | |
sleep 1 | |
socket.puts "." | |
puts "Finished at #{Time.now.strftime('%T.%L')}" | |
socket.close |
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
$ rackup server.ru | |
Starting at 17:49:14.062 | |
Finished at 17:49:14.062 | |
::1 - - [11/Oct/2017:17:49:14 +1300] "POST / HTTP/1.1" 200 - 0.0007 | |
$ ruby client.rb | |
Sending headers at 17:49:12.059 | |
Sending at 17:49:13.060 | |
Finished at 17:49:14.061 |
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
class Middleware | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
puts "Starting at #{Time.now.strftime('%T.%L')}" | |
result = @app.call(env) | |
puts "Finished at #{Time.now.strftime('%T.%L')}" | |
result | |
end | |
end | |
use Middleware | |
run -> (_) { [200, {}, ['OK']] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment