Module: MiddleSquid::Actions
- Included in:
- Runner
- Defined in:
- lib/middle_squid/actions.rb
Predefined Actions collapse
-
#accept ⇒ Object
Allow the request to pass through.
-
#intercept {|req, res| ... } ⇒ Object
Hijack the request and generate a dynamic reply.
-
#redirect_to(url, status: 301) ⇒ Object
Redirect the browser to another URL.
-
#replace_by(url) ⇒ Object
Serve another page in place of the requested one.
Instance Method Details
#accept ⇒ Object
Allow the request to pass through. This is the default action.
12 13 14 |
# File 'lib/middle_squid/actions.rb', line 12 def accept action :accept end |
#intercept {|req, res| ... } ⇒ Object
With great power comes great responsibility. Please respect the privacy of your users.
Hijack the request and generate a dynamic reply. This can be used to skip landing pages, change the behaviour of a website depending on the browser’s headers or to generate an entire virtual website using your favorite Rack framework.
The block is called inside a fiber. If the return value is a Rack triplet, it will be sent to the browser.
61 62 63 64 65 66 67 |
# File 'lib/middle_squid/actions.rb', line 61 def intercept(&block) raise ArgumentError, 'no block given' unless block_given? token = server.token_for block replace_by "http://#{server.host}:#{server.port}/#{token}" end |
#redirect_to(url, status: 301) ⇒ Object
Redirect the browser to another URL.
24 25 26 |
# File 'lib/middle_squid/actions.rb', line 24 def redirect_to(url, status: 301) action :redirect, status: status, url: url end |
#replace_by(url) ⇒ Object
Serve another page in place of the requested one. Avoid in favor of #redirect_to when possible.
36 37 38 |
# File 'lib/middle_squid/actions.rb', line 36 def replace_by(url) action :replace, url: url end |