mirror of
https://github.com/discourse/discourse.git
synced 2025-03-23 20:46:07 +08:00
FIX: Do not consider mobile app traffic as crawler visits
Followup to a4eb523a
This commit is contained in:
parent
f3f04f1643
commit
74869b8a7f
@ -66,7 +66,7 @@ module Middleware
|
|||||||
if @env[DISCOURSE_RENDER] == "crawler" || CrawlerDetection.crawler?(user_agent, @env["HTTP_VIA"])
|
if @env[DISCOURSE_RENDER] == "crawler" || CrawlerDetection.crawler?(user_agent, @env["HTTP_VIA"])
|
||||||
:true
|
:true
|
||||||
else
|
else
|
||||||
user_agent.downcase.include?("discourse") ? :true : :false
|
user_agent.downcase.include?("discourse") && !user_agent.downcase.include?("mobile") ? :true : :false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@is_crawler == :true
|
@is_crawler == :true
|
||||||
|
@ -68,17 +68,30 @@ describe Middleware::RequestTracker do
|
|||||||
expect(ApplicationRequest.page_view_crawler.first.count).to eq(1)
|
expect(ApplicationRequest.page_view_crawler.first.count).to eq(1)
|
||||||
expect(ApplicationRequest.page_view_anon_mobile.first.count).to eq(1)
|
expect(ApplicationRequest.page_view_anon_mobile.first.count).to eq(1)
|
||||||
|
|
||||||
# log discourse User Agent requests as crawler for page views
|
expect(ApplicationRequest.page_view_crawler.first.count).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can log Discourse user agent requests correctly" do
|
||||||
|
# log discourse api agents as crawlers for page view stats...
|
||||||
data = Middleware::RequestTracker.get_data(env(
|
data = Middleware::RequestTracker.get_data(env(
|
||||||
"HTTP_USER_AGENT" => "DiscourseAPI Ruby Gem 0.19.0"
|
"HTTP_USER_AGENT" => "DiscourseAPI Ruby Gem 0.19.0"
|
||||||
), ["200", { "Content-Type" => 'text/html' }], 0.1)
|
), ["200", { "Content-Type" => 'text/html' }], 0.1)
|
||||||
|
|
||||||
Middleware::RequestTracker.log_request(data)
|
Middleware::RequestTracker.log_request(data)
|
||||||
ApplicationRequest.write_cache!
|
ApplicationRequest.write_cache!
|
||||||
|
expect(ApplicationRequest.page_view_crawler.first.count).to eq(1)
|
||||||
|
|
||||||
expect(ApplicationRequest.page_view_crawler.first.count).to eq(2)
|
# ...but count our mobile app user agents as regular visits
|
||||||
|
data = Middleware::RequestTracker.get_data(env(
|
||||||
|
"HTTP_USER_AGENT" => "Mozilla/5.0 AppleWebKit/605.1.15 Mobile/15E148 DiscourseHub)"
|
||||||
|
), ["200", { "Content-Type" => 'text/html' }], 0.1)
|
||||||
|
|
||||||
|
Middleware::RequestTracker.log_request(data)
|
||||||
|
ApplicationRequest.write_cache!
|
||||||
|
|
||||||
|
expect(ApplicationRequest.page_view_crawler.first.count).to eq(1)
|
||||||
|
expect(ApplicationRequest.page_view_anon.first.count).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "rate limiting" do
|
context "rate limiting" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user