Sha256: f2029e2e487960458a0583682a888e93884180b290b877082e24b843021bebd1

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'wovnrb'

module Wovn
  module ReverseProxy
    # Fixed Wovnrb for reverse proxy.
    class Wovnrb < Wovnrb::Interceptor
      def initialize(app, opts = {})
        super
        @setting_keys = @store.instance_eval { @settings.keys }
      end

      def call(env)
        opts = get_wovn_settings(env)
        @store.reset
        @store.settings(opts)
        super
      end

      private

      def get_wovn_settings(env)
        @setting_keys.each_with_object({}) do |key, params|
          env_key = "HTTP_X_WOVN_#{key.upcase}"
          value = env[env_key]
          next unless value
          params[key] = get_appropriate_value(key, value)
        end
      end

      def get_appropriate_value(key, value)
        if key == 'query' || key == 'supported_langs'
          value = value.split(/,/)
        elsif key == 'test_mode' || key == 'use_proxy'
          value = true? value
        end
        value
      end

      def true?(value)
        return true if value.to_s.casecmp('true').zero?
        return true if value.to_s.casecmp('on').zero?
        return true if value.to_s == '1'
        false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wovn-reverse_proxy-0.1.0 lib/wovn/reverse_proxy/wovnrb.rb