Skip to content

Commit

Permalink
Merge pull request #146 from george-gca/patch-1
Browse files Browse the repository at this point in the history
Added `user_agent` as an option to Parser
  • Loading branch information
grosser authored Apr 6, 2024
2 parents deaae98 + cdb459f commit 951fa17
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Unreleased

* Added `user_agent` as an option to Parser [#146](https://github.com/premailer/css_parser/pull/146)

### Version v1.16.0

* Fix parsing space-less media query features like `@media(width:123px)` [#141](https://github.com/premailer/css_parser/pull/141)
Expand Down
6 changes: 3 additions & 3 deletions lib/css_parser/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class CircularReferenceError < StandardError; end
# [<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

Expand All @@ -40,7 +39,8 @@ def initialize(options = {})
import: true,
io_exceptions: true,
rule_set_exceptions: true,
capture_offsets: false}.merge(options)
capture_offsets: false,
user_agent: USER_AGENT}.merge(options)

# array of RuleSets
@rules = []
Expand Down Expand Up @@ -597,7 +597,7 @@ def read_remote_file(uri) # :nodoc:
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'

Expand Down

0 comments on commit 951fa17

Please sign in to comment.