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>
This commit is contained in:
Ben Halpern 2023-05-17 15:49:35 -04:00 committed by GitHub
parent f85db74b92
commit 27d6fbb285
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View file

@ -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

View file

@ -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(