Class: BallonizerProxy

Inherits:
PrettyProxy
  • Object
show all
Defined in:
lib/ballonizer_proxy.rb

Overview

A PrettyProxy (that is a Rack::Proxy, that is a rack app) subclass that use an Ballonizer instance to allow the addition of speech bubbles (text ballons) over any (X)HTML page that is requested through it.

The first three parameters are equal to the PrettyProxy ones, and the last two equal the Ballonizer ones. This class only deal in a special way with the *_asset_path_for_link and form_handler_url that are joined with the proxy site (scheme+host+port) to make a absolute url if the original values are relative.

Author:

  • Henrique Becker

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proxy_path, original_domain, original_paths, database, settings) ⇒ BallonizerProxy

Returns a new instance of BallonizerProxy.



21
22
23
24
# File 'lib/ballonizer_proxy.rb', line 21

def initialize(proxy_path, original_domain, original_paths, database, settings)
  super(proxy_path, original_domain, original_paths, true)
  @ballonizer = Ballonizer.new(database, settings)
end

Instance Attribute Details

#ballonizerObject (readonly)

Returns the value of attribute ballonizer.



19
20
21
# File 'lib/ballonizer_proxy.rb', line 19

def ballonizer
  @ballonizer
end

Instance Method Details

#sugared_rewrite_response(triplet, requested_to_proxy_env, rewritten_env) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ballonizer_proxy.rb', line 26

def sugared_rewrite_response(triplet, requested_to_proxy_env, rewritten_env)
  status, headers, page = triplet
  original_url = Rack::Request.new(rewritten_env).url
  requested_to_proxy_url = Rack::Request.new(requested_to_proxy_env).url
  proxy_site = Addressable::URI.parse(requested_to_proxy_url).site

  absolute_settings = {}
  [ :css_asset_path_for_link,
    :js_asset_path_for_link,
    :form_handler_url].each do | conf_name |
    relative_uri = @ballonizer.settings[conf_name]
    next unless relative_uri 
    absolute_settings[conf_name] = Addressable::URI.parse(proxy_site)
                                                   .join(relative_uri).to_s
  end

  page = @ballonizer.ballonize_page(
    page, original_url, headers['content-type'], absolute_settings
  )

  # This makes the browser always request a new copy of the document (status
  # 200) and avoid 304 status without body to us ballonize (and the ballons
  # can be updated without the original page being updated so isn't
  # interesting to preserve the original cache control)
  Workarounds.make_uncacheable(headers)

  triplet = [status, headers, page]
end