Typhoeus cache class
This commit is contained in:
@@ -17,6 +17,8 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#++
|
#++
|
||||||
|
|
||||||
|
require 'common/typhoeus_cache'
|
||||||
|
|
||||||
class Browser
|
class Browser
|
||||||
@@instance = nil
|
@@instance = nil
|
||||||
USER_AGENT_MODES = %w{ static semi-static random }
|
USER_AGENT_MODES = %w{ static semi-static random }
|
||||||
@@ -51,12 +53,12 @@ class Browser
|
|||||||
#connecttimeout: @request_timeout
|
#connecttimeout: @request_timeout
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO : add an option for the cache dir instead of using a constant
|
# TODO : add an argument for the cache dir instead of using a constant
|
||||||
@cache = CacheFileStore.new(CACHE_DIR + '/browser')
|
@cache = TyphoeusCache.new(CACHE_DIR + '/browser')
|
||||||
|
|
||||||
@cache.clean
|
@cache.clean
|
||||||
|
|
||||||
#Typhoeus::Config.cache = @cache
|
Typhoeus::Config.cache = @cache
|
||||||
end
|
end
|
||||||
|
|
||||||
private_class_method :new
|
private_class_method :new
|
||||||
@@ -199,15 +201,15 @@ class Browser
|
|||||||
end
|
end
|
||||||
|
|
||||||
if !params.has_key?(:headers)
|
if !params.has_key?(:headers)
|
||||||
params = params.merge(:headers => {'user-agent' => self.user_agent})
|
params = params.merge(:headers => {'ser-agent' => self.user_agent})
|
||||||
elsif !params[:headers].has_key?('user-agent')
|
elsif !params[:headers].has_key?('user-agent')
|
||||||
params[:headers]['user-agent'] = self.user_agent
|
params[:headers]['user-agent'] = self.user_agent
|
||||||
end
|
end
|
||||||
|
|
||||||
# Used to enable the cache system if :cache_timeout > 0
|
# Used to enable the cache system if :cache_timeout > 0
|
||||||
#unless params.has_key?(:cache_ttl)
|
unless params.has_key?(:cache_ttl)
|
||||||
# params = params.merge(cache_ttl: @cache_timeout)
|
params = params.merge(cache_ttl: @cache_timeout)
|
||||||
#end
|
end
|
||||||
|
|
||||||
params
|
params
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class CacheFileStore
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_entry_file_path(key)
|
def get_entry_file_path(key)
|
||||||
@storage_path + '/' + key
|
File::join(@storage_path, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
32
lib/common/typhoeus_cache.rb
Normal file
32
lib/common/typhoeus_cache.rb
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# encoding: UTF-8
|
||||||
|
#--
|
||||||
|
# WPScan - WordPress Security Scanner
|
||||||
|
# Copyright (C) 2012-2013
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#++
|
||||||
|
|
||||||
|
require 'common/cache_file_store'
|
||||||
|
|
||||||
|
class TyphoeusCache < CacheFileStore
|
||||||
|
|
||||||
|
def get(request)
|
||||||
|
read_entry(request.hash.to_s)
|
||||||
|
end
|
||||||
|
|
||||||
|
def set(request, response)
|
||||||
|
write_entry(request.hash.to_s, response, request.cache_ttl)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -34,13 +34,11 @@ begin
|
|||||||
require 'rbconfig'
|
require 'rbconfig'
|
||||||
require 'pp'
|
require 'pp'
|
||||||
# Third party libs
|
# Third party libs
|
||||||
#gem 'typhoeus', :git => "https://github.com/typhoeus/typhoeus.git"
|
|
||||||
require 'typhoeus'
|
require 'typhoeus'
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'nokogiri'
|
require 'nokogiri'
|
||||||
# Custom libs
|
# Custom libs
|
||||||
require 'common/browser'
|
require 'common/browser'
|
||||||
require 'common/cache_file_store'
|
|
||||||
require 'common/custom_option_parser'
|
require 'common/custom_option_parser'
|
||||||
rescue LoadError => e
|
rescue LoadError => e
|
||||||
puts "[ERROR] #{e}"
|
puts "[ERROR] #{e}"
|
||||||
|
|||||||
3
spec/lib/common/typhoeus_cache_spec.rb
Normal file
3
spec/lib/common/typhoeus_cache_spec.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# encoding: UTF-8
|
||||||
|
|
||||||
|
# TODO
|
||||||
Reference in New Issue
Block a user