SlideShare a Scribd company logo
1 of 40
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
   and many more!
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
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 your thingy here)
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!



                           I hates this
#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
#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 request. And it was something you
        wanted to get hit every five minutes.
#2 Rack::Regenerate
       http://github.com/joshbuddy/rack-regenerate
X-Cache-Regenerate: [interval in seconds] [number of times to call]
#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
#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
#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 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 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
#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!
#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

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


  Middleware
                               Who’s that
         Middleware
                               middleware
Middleware
                                    ?
  Middleware
#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
#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


                                         STALE!



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




    Request                       Cache                Application
                                          Revalidate
               Serve stale data
The End?

More Related Content

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Featured

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

Stupid Middleware Tricks

Editor's Notes