Skip to content

Instantly share code, notes, and snippets.

@Aupajo
Last active October 11, 2017 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aupajo/aeba7dc6ce0aed678c989d39c75a7740 to your computer and use it in GitHub Desktop.
Save Aupajo/aeba7dc6ce0aed678c989d39c75a7740 to your computer and use it in GitHub Desktop.
Rack timings
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
$ 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
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