SlideShare una empresa de Scribd logo
1 de 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?

Más contenido relacionado

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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...
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
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...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

Destacado

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)
 

Destacado (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

Notas del editor