From 2cc9a55f3745e2069a6fd1c3537a2f0fc8bb8b4b Mon Sep 17 00:00:00 2001 From: Andy Waite Date: Wed, 17 Apr 2024 15:28:25 -0400 Subject: [PATCH] Set user agent for api.rubyonrails.org (#343) --- lib/ruby_lsp/ruby_lsp_rails/support/rails_document_client.rb | 5 ++++- test/ruby_lsp_rails/hover_test.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ruby_lsp/ruby_lsp_rails/support/rails_document_client.rb b/lib/ruby_lsp/ruby_lsp_rails/support/rails_document_client.rb index e9573bdb..6e80f0a5 100644 --- a/lib/ruby_lsp/ruby_lsp_rails/support/rails_document_client.rb +++ b/lib/ruby_lsp/ruby_lsp_rails/support/rails_document_client.rb @@ -68,7 +68,10 @@ def generate_rails_document_urls(name) $stderr.puts("Fetching search index for Rails documentation") - response = Net::HTTP.get_response(URI("#{RAILS_DOC_HOST}/v#{RAILTIES_VERSION}/js/search_index.js")) + response = Net::HTTP.get_response( + URI("#{RAILS_DOC_HOST}/v#{RAILTIES_VERSION}/js/search_index.js"), + { "User-Agent" => "ruby-lsp-rails/#{RubyLsp::Rails::VERSION}" }, + ) body = case response when Net::HTTPSuccess diff --git a/test/ruby_lsp_rails/hover_test.rb b/test/ruby_lsp_rails/hover_test.rb index 83840fa8..bab6ad4a 100644 --- a/test/ruby_lsp_rails/hover_test.rb +++ b/test/ruby_lsp_rails/hover_test.rb @@ -12,7 +12,7 @@ class HoverTest < ActiveSupport::TestCase .with( headers: { "Host" => "api.rubyonrails.org", - "User-Agent" => "Ruby", + "User-Agent" => %r{^ruby-lsp-rails\/.*$}, }, ) .to_return(status: 200, body: body, headers: {})