From 27d6fbb28548c320a3d261d673a3a4781f363bcb Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Wed, 17 May 2023 15:49:35 -0400 Subject: [PATCH] Send user agent in open graph fetch so we don't block our own requests (#19462) * Send user agent in open graph fetch * Update app/services/open_graph.rb Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Change user agent and test --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- app/services/open_graph.rb | 3 ++- spec/liquid_tags/unified_embed/tag_spec.rb | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/services/open_graph.rb b/app/services/open_graph.rb index 3e0849c65..990251817 100644 --- a/app/services/open_graph.rb +++ b/app/services/open_graph.rb @@ -85,7 +85,8 @@ class OpenGraph def fetch_html(url) Rails.cache.fetch("#{url}_open_graph_html", expires_in: CACHE_EXPIRY_IN_MINUTES.minutes) do - Net::HTTP.get(URI(url)) + response = HTTParty.get(url, headers: { "User-Agent" => "#{Settings::Community.community_name} (#{URL.url})" }) + response&.body end end diff --git a/spec/liquid_tags/unified_embed/tag_spec.rb b/spec/liquid_tags/unified_embed/tag_spec.rb index 60fd7d05e..a4ada6ecc 100644 --- a/spec/liquid_tags/unified_embed/tag_spec.rb +++ b/spec/liquid_tags/unified_embed/tag_spec.rb @@ -22,8 +22,7 @@ RSpec.describe UnifiedEmbed::Tag, type: :liquid_tag do headers: { "Accept" => "*/*", "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", - "Host" => "guides.rubyonrails.org", - "User-Agent" => "Ruby" + "User-Agent" => "DEV(local) (http://localhost:3000)" }, ) .to_return(