Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Rack

1,579 views

Published on

广州 ruby 爱好者聚会上五分钟 topic

http://github.com/shaokun/rack-demo

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Rack

  1. 1. Rack Shaokun Wu shaokun@kudelabs.com
  2. 2. • web framework • frameworkless web application
  3. 3. • web servers WEBrick, Mongrel, Thin, Passenger... • web server handlers
  4. 4. ??? •n frameworks •m web servers • web server handlers
  5. 5. n*m
  6. 6. n * m => n + m
  7. 7. HTTP Request => Response
  8. 8. Request • GET / HTTP/1.1 User-Agent: curl/7.12.2 ... Host: ruby-lang.org Pragma: no-cache Accept: */*
  9. 9. Response • HTTP/1.1 302 Found • Date: Sat, 27 Oct 2007 10:07:53 GMT Server: Apache/2.0.54 (Debian GNU/Linux) mod_ssl/2.0.54 OpenSSL/0.9.7e Location: http://www.ruby-lang.org/ Content-Length: 209 Content-Type: text/html; charset=iso-8859-1 • <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>302 Found</title> </head><body> <h1>Found</h1> <p>The document has moved <a href="http://www.ruby-lang.org/">here</ a>.</p> </body></html>
  10. 10. Response • Status Code to_i • Headers each yields key-value pairs • Body each yields strings
  11. 11. [status, headers, body]
  12. 12. Rack • • HTTP Ruby API
  13. 13. Hello Rack! • lambda { |env| [200, # Status Code {"Content-Type"=>"text/plain"}, # Headers ["Hello, world!"]] # Body }
  14. 14. Rack Handlers • CGI • EventedMongrel • FastCGI • LSWS • Mongrel • SCGI • SwiftipliedMongrel • Thin • WEBrick
  15. 15. • Rack::Cascade • Rack::CommonLogger • Rack::Lint • Rack::Recursive • Rack::Reloader • Rack::ShowException • Rack::ShowStatus • Rack::Static • Rack::URLMap • http://coderack.org/middlewares
  16. 16. Let’s code!
  17. 17. Hello Rack!
  18. 18. Response Timer
  19. 19. .NET or J2EE in one second
  20. 20. No IE 6 Please!!!!!!!!!!
  21. 21. Thanks! shaokun@kudelabs.com

×