Skip to content

Commit

Permalink
Add User-Agent header to requests and introduce delay in dependencies…
Browse files Browse the repository at this point in the history
… metadata retrieval in cargo
  • Loading branch information
andrew committed Feb 27, 2025
1 parent 2e0c063 commit 2a316fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/models/ecosystem/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,15 @@ def get_raw(url, options = {})
end

def request(url, options = {})
options[:headers] ||= {}
options[:headers]["User-Agent"] = "packages.ecosyste.ms ([email protected])"
connection = Faraday.new url.strip, options do |builder|
builder.use Faraday::FollowRedirects::Middleware
builder.request :retry, { max: 5, interval: 0.05, interval_randomness: 0.5, backoff_factor: 2 }

builder.request :instrumentation
builder.adapter Faraday.default_adapter, accept_encoding: "gzip"

end
connection.get
end
Expand Down
1 change: 1 addition & 0 deletions app/models/ecosystem/cargo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def versions_metadata(pkg_metadata, existing_version_numbers = [])
end

def dependencies_metadata(name, version, _package)
sleep 1
deps = get("#{@registry_url}/api/v1/crates/#{name}/#{version}/dependencies")["dependencies"]
return [] if deps.nil?

Expand Down

0 comments on commit 2a316fc

Please sign in to comment.