A platform for community discussion. Free, open, simple.
FIX: add 'noindex' header to rss feed responses.
Vinoth Kannanb6765aac4b53
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex 27810f9e718..c6cfcf31652 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -44,6 +44,7 @@ class ApplicationController < ActionController::Baseafter_action :perform_refresh_sessionafter_action :dont_cache_pageafter_action :conditionally_allow_site_embedding+ after_action :add_noindex_header, if: -> { is_feed_request? }layout :set_layout@@ -801,6 +802,14 @@ class ApplicationController < ActionController::Baserequest.env['DISCOURSE_IS_ASSET_PATH'] = 1end+ def is_feed_request?+ request.format.atom? || request.format.rss?+ end++ def add_noindex_header+ response.headers['X-Robots-Tag'] = 'noindex'+ end+protecteddef render_post_json(post, add_raw: true)diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex 774b7ed82ce..40c84cad799 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -47,6 +47,8 @@ class UsersController < ApplicationController:admin_login,:confirm_admin]+ after_action :add_noindex_header, only: [:show]+def indexend@@ -73,8 +75,6 @@ class UsersController < ApplicationControllertrack_visit_to_user_profileend- response.headers['X-Robots-Tag'] = 'noindex'-# This is a hack to get around a Rails issue where values with periods aren't handled correctly# when used as part of a route.if params[:external_id] && params[:external_id].ends_with?('.json')diff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rbindex 3897f03abcb..5172969289f 100644--- a/spec/requests/list_controller_spec.rb+++ b/spec/requests/list_controller_spec.rb@@ -300,6 +300,7 @@ RSpec.describe ListController doget "/latest.rss"expect(response.status).to eq(200)expect(response.media_type).to eq('application/rss+xml')+ expect(response.headers['X-Robots-Tag']).to eq('noindex')endit 'renders links correctly with subfolder' do