0
Stupid Rack
Middleware
   Tricks
josh@aiderss.com
@joshbuddy
http://github.com/joshbuddy
What is Rack?
What is Rack?
Standard interface for HTTP servers and application.
What is Rack?
Standard interface for HTTP servers and application.

    CGI, FastCGI,
    Mongrel, Thin,
      WEBrick
   ...
What is Rack?
Standard interface for HTTP servers and application.

    CGI, FastCGI,                Rails, Merb,
    Mong...
What is Rack
Middleware?
What is Rack
          Middleware?

HTTP Server
What is Rack
          Middleware?

HTTP Server          Application
What is Rack
          Middleware?

HTTP Server          Application
What is Rack
Middleware?
    Transparent
    Intercepting
      Caching
   Content filtering
What is Rack
Middleware?
         Transparent
         Intercepting
           Caching
      Content filtering
  (insert yo...
My Challenge
My Challenge
 I'm going to write a
      new Rack
     Middleware
     everyday of
      RailsConf.
My Challenge
 I'm going to write a
      new Rack
     Middleware
     everyday of
      RailsConf.
     (with tests)
#1 Rack::Rewrite
http://github.com/joshbuddy/rack-rewrite
#1 Rack::Rewrite
http://github.com/joshbuddy/rack-rewrite
          Get a request, rewrite it!
#1 Rack::Rewrite
http://github.com/joshbuddy/rack-rewrite
          Get a request, rewrite it!



                        ...
#1 Rack::Rewrite
   http://github.com/joshbuddy/rack-rewrite
use Rack::Rewrite do

 on :method => 'get' do

   # If the re...
#2 Rack::Regenerate
http://github.com/joshbuddy/rack-regenerate
#2 Rack::Regenerate
   http://github.com/joshbuddy/rack-regenerate


                     No idea.

But say you had a requ...
#2 Rack::Regenerate
       http://github.com/joshbuddy/rack-regenerate
X-Cache-Regenerate: [interval in seconds] [number o...
#2 Rack::Regenerate
       http://github.com/joshbuddy/rack-regenerate
X-Cache-Regenerate: [interval in seconds] [number o...
#2 Rack::Regenerate
       http://github.com/joshbuddy/rack-regenerate
X-Cache-Regenerate: [interval in seconds] [number o...
#2 Rack::Regenerate
       http://github.com/joshbuddy/rack-regenerate
X-Cache-Regenerate: [interval in seconds] [number o...
#2 Rack::Regenerate
       http://github.com/joshbuddy/rack-regenerate
X-Cache-Regenerate: [interval in seconds] [number o...
#2 Rack::Regenerate
       http://github.com/joshbuddy/rack-regenerate
X-Cache-Regenerate: [interval in seconds] [number o...
#2 Rack::Regenerate
       http://github.com/joshbuddy/rack-regenerate
X-Cache-Regenerate: [interval in seconds] [number o...
#3 Rack::Capabilities
http://github.com/joshbuddy/rack-capabilities
#3 Rack::Capabilities
http://github.com/joshbuddy/rack-capabilities


 Middleware
#3 Rack::Capabilities
http://github.com/joshbuddy/rack-capabilities


 Middleware
         Middleware
#3 Rack::Capabilities
http://github.com/joshbuddy/rack-capabilities


  Middleware
         Middleware
Middleware
#3 Rack::Capabilities
http://github.com/joshbuddy/rack-capabilities


  Middleware
         Middleware
Middleware

  Middl...
#3 Rack::Capabilities
http://github.com/joshbuddy/rack-capabilities


  Middleware
                               Who’s th...
#3 Rack::Capabilities
http://github.com/joshbuddy/rack-capabilities

    # who is before me?
    Rack::Capabilities.before...
#4 Rack::CacheWhileRevalidate
http://github.com/joshbuddy/rack-cache-while-revalidate
#4 Rack::CacheWhileRevalidate
http://github.com/joshbuddy/rack-cache-while-revalidate




    Request
#4 Rack::CacheWhileRevalidate
http://github.com/joshbuddy/rack-cache-while-revalidate




    Request               Cache
#4 Rack::CacheWhileRevalidate
http://github.com/joshbuddy/rack-cache-while-revalidate


                                  ...
#4 Rack::CacheWhileRevalidate
http://github.com/joshbuddy/rack-cache-while-revalidate




    Request                     ...
The End?
Upcoming SlideShare
Loading in...5
×

Stupid Middleware Tricks

2,545

Published on

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

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,545
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
35
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide








































  • Transcript of "Stupid Middleware Tricks"

    1. 1. Stupid Rack Middleware Tricks josh@aiderss.com @joshbuddy http://github.com/joshbuddy
    2. 2. What is Rack?
    3. 3. What is Rack? Standard interface for HTTP servers and application.
    4. 4. What is Rack? Standard interface for HTTP servers and application. CGI, FastCGI, Mongrel, Thin, WEBrick and many more!
    5. 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. 6. What is Rack Middleware?
    7. 7. What is Rack Middleware? HTTP Server
    8. 8. What is Rack Middleware? HTTP Server Application
    9. 9. What is Rack Middleware? HTTP Server Application
    10. 10. What is Rack Middleware? Transparent Intercepting Caching Content filtering
    11. 11. What is Rack Middleware? Transparent Intercepting Caching Content filtering (insert your thingy here)
    12. 12. My Challenge
    13. 13. My Challenge I'm going to write a new Rack Middleware everyday of RailsConf.
    14. 14. My Challenge I'm going to write a new Rack Middleware everyday of RailsConf. (with tests)
    15. 15. #1 Rack::Rewrite http://github.com/joshbuddy/rack-rewrite
    16. 16. #1 Rack::Rewrite http://github.com/joshbuddy/rack-rewrite Get a request, rewrite it!
    17. 17. #1 Rack::Rewrite http://github.com/joshbuddy/rack-rewrite Get a request, rewrite it! I hates this
    18. 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. 19. #2 Rack::Regenerate http://github.com/joshbuddy/rack-regenerate
    20. 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. 21. #2 Rack::Regenerate http://github.com/joshbuddy/rack-regenerate X-Cache-Regenerate: [interval in seconds] [number of times to call]
    22. 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. 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. 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. 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. 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. 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. 28. #3 Rack::Capabilities http://github.com/joshbuddy/rack-capabilities
    29. 29. #3 Rack::Capabilities http://github.com/joshbuddy/rack-capabilities Middleware
    30. 30. #3 Rack::Capabilities http://github.com/joshbuddy/rack-capabilities Middleware Middleware
    31. 31. #3 Rack::Capabilities http://github.com/joshbuddy/rack-capabilities Middleware Middleware Middleware
    32. 32. #3 Rack::Capabilities http://github.com/joshbuddy/rack-capabilities Middleware Middleware Middleware Middleware
    33. 33. #3 Rack::Capabilities http://github.com/joshbuddy/rack-capabilities Middleware Who’s that Middleware middleware Middleware ? Middleware
    34. 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. 35. #4 Rack::CacheWhileRevalidate http://github.com/joshbuddy/rack-cache-while-revalidate
    36. 36. #4 Rack::CacheWhileRevalidate http://github.com/joshbuddy/rack-cache-while-revalidate Request
    37. 37. #4 Rack::CacheWhileRevalidate http://github.com/joshbuddy/rack-cache-while-revalidate Request Cache
    38. 38. #4 Rack::CacheWhileRevalidate http://github.com/joshbuddy/rack-cache-while-revalidate STALE! Request Cache
    39. 39. #4 Rack::CacheWhileRevalidate http://github.com/joshbuddy/rack-cache-while-revalidate Request Cache Application Revalidate Serve stale data
    40. 40. The End?
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×