Stupid Middleware Tricks

  • 2,500 views
Uploaded on

My challenge, new middleware everyday. Here is my lightning talk about writing weird Rack Middlewares

My challenge, new middleware everyday. Here is my lightning talk about writing weird Rack Middlewares

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,500
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
34
Comments
0
Likes
5

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide








































Transcript

  • 1. Stupid Rack Middleware Tricks josh@aiderss.com @joshbuddy http://github.com/joshbuddy
  • 2. What is Rack?
  • 3. What is Rack? Standard interface for HTTP servers and application.
  • 4. What is Rack? Standard interface for HTTP servers and application. CGI, FastCGI, Mongrel, Thin, WEBrick and many more!
  • 5. What is Rack? Standard interface for HTTP servers and application. CGI, FastCGI, Rails, Merb, Mongrel, Thin, Sinatra, Ramaze, WEBrick a proc and many more! your next great framework
  • 6. What is Rack Middleware?
  • 7. What is Rack Middleware? HTTP Server
  • 8. What is Rack Middleware? HTTP Server Application
  • 9. What is Rack Middleware? HTTP Server Application
  • 10. What is Rack Middleware? Transparent Intercepting Caching Content filtering
  • 11. What is Rack Middleware? Transparent Intercepting Caching Content filtering (insert your thingy here)
  • 12. My Challenge
  • 13. My Challenge I'm going to write a new Rack Middleware everyday of RailsConf.
  • 14. My Challenge I'm going to write a new Rack Middleware everyday of RailsConf. (with tests)
  • 15. #1 Rack::Rewrite http://github.com/joshbuddy/rack-rewrite
  • 16. #1 Rack::Rewrite http://github.com/joshbuddy/rack-rewrite Get a request, rewrite it!
  • 17. #1 Rack::Rewrite http://github.com/joshbuddy/rack-rewrite Get a request, rewrite it! I hates this
  • 18. #1 Rack::Rewrite http://github.com/joshbuddy/rack-rewrite use Rack::Rewrite do on :method => 'get' do # If the request has a has a param of kitten=cute or # kitten=happy, lets log it and pass it on! # on :params => {:kitten => /cute|happy/} do act { log('what a nice cat') } pass end fail end end
  • 19. #2 Rack::Regenerate http://github.com/joshbuddy/rack-regenerate
  • 20. #2 Rack::Regenerate http://github.com/joshbuddy/rack-regenerate No idea. But say you had a request. And it was something you wanted to get hit every five minutes.
  • 21. #2 Rack::Regenerate http://github.com/joshbuddy/rack-regenerate X-Cache-Regenerate: [interval in seconds] [number of times to call]
  • 22. #2 Rack::Regenerate http://github.com/joshbuddy/rack-regenerate X-Cache-Regenerate: [interval in seconds] [number of times to call] X-Cache-Regenerate: 2 5 Request
  • 23. #2 Rack::Regenerate http://github.com/joshbuddy/rack-regenerate X-Cache-Regenerate: [interval in seconds] [number of times to call] X-Cache-Regenerate: 2 5 Request Response
  • 24. #2 Rack::Regenerate http://github.com/joshbuddy/rack-regenerate X-Cache-Regenerate: [interval in seconds] [number of times to call] X-Cache-Regenerate: 2 5 Request Response Intercept
  • 25. #2 Rack::Regenerate http://github.com/joshbuddy/rack-regenerate X-Cache-Regenerate: [interval in seconds] [number of times to call] X-Cache-Regenerate: 2 5 Request Response Intercept 2 seconds
  • 26. #2 Rack::Regenerate http://github.com/joshbuddy/rack-regenerate X-Cache-Regenerate: [interval in seconds] [number of times to call] X-Cache-Regenerate: 2 5 Request Response Intercept 2 seconds 2 seconds
  • 27. #2 Rack::Regenerate http://github.com/joshbuddy/rack-regenerate X-Cache-Regenerate: [interval in seconds] [number of times to call] X-Cache-Regenerate: 2 5 Request Response Intercept 2 seconds 2 seconds 5.times!
  • 28. #3 Rack::Capabilities http://github.com/joshbuddy/rack-capabilities
  • 29. #3 Rack::Capabilities http://github.com/joshbuddy/rack-capabilities Middleware
  • 30. #3 Rack::Capabilities http://github.com/joshbuddy/rack-capabilities Middleware Middleware
  • 31. #3 Rack::Capabilities http://github.com/joshbuddy/rack-capabilities Middleware Middleware Middleware
  • 32. #3 Rack::Capabilities http://github.com/joshbuddy/rack-capabilities Middleware Middleware Middleware Middleware
  • 33. #3 Rack::Capabilities http://github.com/joshbuddy/rack-capabilities Middleware Who’s that Middleware middleware Middleware ? Middleware
  • 34. #3 Rack::Capabilities http://github.com/joshbuddy/rack-capabilities # who is before me? Rack::Capabilities.before(self) # who is after me? Rack::Capabilities.after(self) # where can I go find AGoodTime? Rack::Capabilities.find(AGoodTime) # ==> nil
  • 35. #4 Rack::CacheWhileRevalidate http://github.com/joshbuddy/rack-cache-while-revalidate
  • 36. #4 Rack::CacheWhileRevalidate http://github.com/joshbuddy/rack-cache-while-revalidate Request
  • 37. #4 Rack::CacheWhileRevalidate http://github.com/joshbuddy/rack-cache-while-revalidate Request Cache
  • 38. #4 Rack::CacheWhileRevalidate http://github.com/joshbuddy/rack-cache-while-revalidate STALE! Request Cache
  • 39. #4 Rack::CacheWhileRevalidate http://github.com/joshbuddy/rack-cache-while-revalidate Request Cache Application Revalidate Serve stale data
  • 40. The End?