Class: Watobo::Interceptor::RequestFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/watobo/core/intercept_filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(parms) ⇒ RequestFilter

Returns a new instance of RequestFilter.


203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/watobo/core/intercept_filter.rb', line 203

def initialize(parms)
  @settings = {
    :site_in_scope => false,
    :method_filter => '(get|post|put)',
    :negate_method_filter => false,
    :negate_url_filter => false,
    :url_filter => '',
    :file_type_filter => '(jpg|gif|png|jpeg|bmp)',
    :negate_file_type_filter => true,

    :parms_filter => '',
    :negate_parms_filter => false
    #:regex_location => 0, # TODO: HEADER_LOCATION, BODY_LOCATION, ALL

  }
  [ :site_in_scope, :method_filter,:negate_method_filter, :negate_url_filter,:url_filter, :file_type_filter,:negate_file_type_filter,:parms_filter,:negate_parms_filter].each do |k|
    @settings[k] = parms[k]
  end
#:regex_location => 0, # TODO: HEADER_LOCATION, BODY_LOCATION, ALL

end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)


227
228
229
230
231
# File 'lib/watobo/core/intercept_filter.rb', line 227

def method_missing(name, *args, &block)
  # puts "* instance method missing (#{name})"
  @settings.has_key? name.to_sym || super
  @settings[name.to_sym]
end

Instance Method Details

#match?(request) ⇒ Boolean

Returns:

  • (Boolean)

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/watobo/core/intercept_filter.rb', line 142

def match?(request)
  match_url = true
  # puts @request_filter_settings.to_yaml

  if url_filter != ''
    match_url = false
    if request.url.to_s =~ /#{url_filter}/i
    match_url = true
    end
    if negate_url_filter == true
    match_url = ( match_url == true ) ? false : true
    end
  end

  return false if match_url == false

  match_method = true

  if method_filter != ''
    match_method = false
    if request.method =~ /#{method_filter}/i
    match_method = true
    end

    if negate_method_filter == true
    match_method = ( match_method == true ) ? false : true
    end
  end

  return false if match_method == false

  match_ftype = true
  ftype_filter = file_type_filter
  if ftype_filter != ''
    match_ftype = false
    if request.doctype != '' and request.doctype =~ /#{ftype_filter}/i
    match_ftype = true
    end
    if negate_file_type_filter == true
    match_ftype = ( match_ftype == true ) ? false : true
    end
  end
  return false if match_ftype == false

  match_parms = true
  # parms_filter = @request_filter_settings[:parms_filter]
  if parms_filter != ''
    # puts "!PARMS FILTER: #{parms_filter}"
    match_parms = false
    puts request.parms
    match_parms = request.parms.find {|x| x =~ /#{parms_filter}/ }
    match_parms = ( match_parms.nil? ) ? false : true
    if negate_parms_filter == true
    match_parms = ( match_parms == true ) ? false : true
    end
  end
  return false if match_parms == false

  true
end