FEATURE: allow view exclusion using custom header

Set Discourse-Track-View to either "0" or "false" to exclude request
This commit is contained in:
Sam
2015-02-26 11:40:57 +11:00
parent 3e2ba5b30b
commit cbe18eb0df
2 changed files with 29 additions and 3 deletions

View File

@ -51,12 +51,18 @@ class Middleware::RequestTracker
helper = Middleware::AnonymousCache::Helper.new(env)
request = Rack::Request.new(env)
env_track_view = env[TRACK_VIEW]
track_view = status == 200
track_view &&= env_track_view != "0".freeze && env_track_view != "false".freeze
track_view &&= env_track_view || (request.get? && !request.xhr? && headers[CONTENT_TYPE] =~ /text\/html/)
{
status: status,
is_crawler: helper.is_crawler?,
has_auth_cookie: helper.has_auth_cookie?,
is_background: request.path =~ /^\/message-bus\// || request.path == /\/topics\/timings/,
track_view: (env[TRACK_VIEW] || (request.get? && !request.xhr? && headers[CONTENT_TYPE] =~ /text\/html/)) && status == 200
track_view: track_view
}
end