lib/css_parser/parser.rb in css_parser-1.16.0 vs lib/css_parser/parser.rb in css_parser-1.17.0
- old
+ new
@@ -15,11 +15,10 @@
# [<tt>absolute_paths</tt>] Convert relative paths to absolute paths (<tt>href</tt>, <tt>src</tt> and <tt>url('')</tt>. Boolean, default is <tt>false</tt>.
# [<tt>import</tt>] Follow <tt>@import</tt> rules. Boolean, default is <tt>true</tt>.
# [<tt>io_exceptions</tt>] Throw an exception if a link can not be found. Boolean, default is <tt>true</tt>.
class Parser
USER_AGENT = "Ruby CSS Parser/#{CssParser::VERSION} (https://github.com/premailer/css_parser)"
-
STRIP_CSS_COMMENTS_RX = %r{/\*.*?\*/}m.freeze
STRIP_HTML_COMMENTS_RX = /<!--|-->/m.freeze
# Initial parsing
RE_AT_IMPORT_RULE = /@import\s*(?:url\s*)?(?:\()?(?:\s*)["']?([^'"\s)]*)["']?\)?([\w\s,^\]()]*)\)?[;\n]?/.freeze
@@ -34,15 +33,18 @@
#++
@folded_declaration_cache = {}
class << self; attr_reader :folded_declaration_cache; end
def initialize(options = {})
- @options = {absolute_paths: false,
- import: true,
- io_exceptions: true,
- rule_set_exceptions: true,
- capture_offsets: false}.merge(options)
+ @options = {
+ absolute_paths: false,
+ import: true,
+ io_exceptions: true,
+ rule_set_exceptions: true,
+ capture_offsets: false,
+ user_agent: USER_AGENT
+ }.merge(options)
# array of RuleSets
@rules = []
@redirect_count = nil
@@ -595,10 +597,10 @@
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
else
http = Net::HTTP.new(uri.host, uri.port)
end
- res = http.get(uri.request_uri, {'User-Agent' => USER_AGENT, 'Accept-Encoding' => 'gzip'})
+ res = http.get(uri.request_uri, {'User-Agent' => @options[:user_agent], 'Accept-Encoding' => 'gzip'})
src = res.body
charset = res.respond_to?(:charset) ? res.encoding : 'utf-8'
if res.code.to_i >= 400
@redirect_count = nil