lib/rack/tracker/handler.rb in rack-tracker-1.6.0 vs lib/rack/tracker/handler.rb in rack-tracker-1.7.0

- old
+ new

@@ -36,10 +36,15 @@ def render Tilt.new(File.join(File.dirname(__FILE__), handler_name, 'template', "#{handler_name}.erb") ).render(self) end def inject(response) + # default to not inject this tracker if the DNT HTTP header is set + # if the DO_NOT_RESPECT_DNT_HEADER config is set the DNT header is ignored :( - please do respect the DNT header! + if self.dnt_header_opt_out? && !self.options.has_key?(:DO_NOT_RESPECT_DNT_HEADER) + return response + end # Sub! is enough, in well formed html there's only one head or body tag. # Block syntax need to be used, otherwise backslashes in input will mess the output. # @see http://stackoverflow.com/a/4149087/518204 and https://github.com/railslove/rack-tracker/issues/50 response.sub! %r{</#{self.position}>} do |m| self.render << m.to_s @@ -66,9 +71,14 @@ if option_value = value.respond_to?(:call) ? value.call(env) : value tracker_options[tracker_option_key(key)] = tracker_option_value(option_value) end end end + end + + # the request has set the DO NOT TRACK (DNT) and has opted to get not tracked (DNT=1) + def dnt_header_opt_out? + self.env['HTTP_DNT'] && self.env['HTTP_DNT'].to_s == '1' end private # Transformations to be applied to tracker option keys.