Class: Ritm::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ritm/configuration.rb

Overview

Global Ritm settings

Constant Summary collapse

DEFAULT_SETTINGS =
{
  proxy: {
    bind_address: '127.0.0.1',
    bind_port: 8080
  },

  ssl_reverse_proxy: {
    bind_address: '127.0.0.1',
    bind_port: 8081,
    ca: {
      pem: nil,
      key: nil
    }
  },

  intercept: {
    # Is interception enabled
    enabled: true,

    # Do not intercept requests whose URLs match/start with the given regex/strings (blacklist)
    skip_urls: [],

    # Intercepts requests whose  URLs match/start with the given regex/strings (whitelist)
    # By default everything will be intercepted.
    intercept_urls: []
  },

  misc: {
    add_request_headers: {},
    add_response_headers: { 'connection' => 'clone' },

    strip_request_headers: [/proxy-*/],
    strip_response_headers: ['strict-transport-security', 'transfer-encoding'],

    unpack_gzip_deflate_in_requests: true,
    unpack_gzip_deflate_in_responses: true,
    process_chunked_encoded_transfer: true
  }
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Configuration

Returns a new instance of Configuration.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ritm/configuration.rb', line 47

def initialize(settings = {})
  settings = DEFAULT_SETTINGS.merge(settings)
  @values = {
    dispatcher: Dispatcher.new,

    # Is interception enabled
    enabled: true
  }

  @settings = settings.to_properties
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



59
60
61
# File 'lib/ritm/configuration.rb', line 59

def method_missing(m, *args, &block)
  @settings.send(m, *args, &block)
end

Instance Method Details

#[](setting) ⇒ Object



63
64
65
# File 'lib/ritm/configuration.rb', line 63

def [](setting)
  @values[setting]
end

#disableObject

Disable interception



73
74
75
# File 'lib/ritm/configuration.rb', line 73

def disable
  @values[:enabled] = false
end

#enableObject

Re-enable interception



68
69
70
# File 'lib/ritm/configuration.rb', line 68

def enable
  @values[:enabled] = true
end