Sha256: edc1d804f78c08d7782790fbc39f9622faddea56667c7944310f0da76388b627

Contents?: true

Size: 1.42 KB

Versions: 5

Compression:

Stored size: 1.42 KB

Contents

module Rtml::Controller::BeforeFilters
  protected
  def rtml_format
    def request.is_terminal?
      self.user_agent and (self.user_agent['OE MicroBrowser'] || self.user_agent['IO Browser'])
    end
    def request.terminal?; is_terminal?; end

    def request.rtml?
      format == :rtml || params[:format] == 'rtml'
    end

    def response.rtml?
      request.is_terminal? || request.format == :rtml || template.template_format == :rtml
    end

    params[:format] = 'rtml' if params[:format] == 'tml'
    return if params[:format]

    if request.format == :tml || request.is_terminal?
      request.format = :rtml
    end
  end

  def set_rtml_etag
    # TODO: The lines below were in RTML 1.x; see if they are necessary now that caching has been addressed.
    headers['Cache-Control'] = 'no-cache '
    headers['ETag'] = "W/\"329-#{Time.now.to_i}#{rand(9999)}\" "
  end

  def set_rtml_headers
    if request.format == 'rtml'
      headers['content-type'] = (request.is_terminal? ? 'text/tml' : 'text/xml')
      headers['Expires'] =
              if expires_at then expires_at.call(self)
              else Time.at(0) # always expired
              end.strftime("%a, %d %b %Y %H:%M:%S GMT")
    end
  end

  public
  class << self
    def included(base)
      base.instance_eval do
        skip_before_filter :verify_authenticity_token
        before_filter :rtml_format
        before_filter :set_rtml_etag
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rtml-2.0.4 lib/rtml/controller/before_filters.rb
rtml-2.0.3 lib/rtml/controller/before_filters.rb
rtml-2.0.2 lib/rtml/controller/before_filters.rb
rtml-2.0.1 lib/rtml/controller/before_filters.rb
rtml-2.0.0.alpha.1 lib/rtml/controller/before_filters.rb