SlideShare a Scribd company logo
1 of 40
Download to read offline
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

20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdfJamie (Taka) Wang
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIUdaiappa Ramachandran
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.francesco barbera
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServicePicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServiceRenan Moreira de Oliveira
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
Things you didn't know you can use in your Salesforce
Things you didn't know you can use in your SalesforceThings you didn't know you can use in your Salesforce
Things you didn't know you can use in your SalesforceMartin Humpolec
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?SANGHEE SHIN
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 

Recently uploaded (20)

20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AI
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServicePicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
Things you didn't know you can use in your Salesforce
Things you didn't know you can use in your SalesforceThings you didn't know you can use in your Salesforce
Things you didn't know you can use in your Salesforce
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 

Stupid Middleware Tricks

Editor's Notes