Skip to content

Commit

Permalink
Merge pull request #434 from niezbop/fix/http/browser_agent
Browse files Browse the repository at this point in the history
[Fix] U3d::Utils: replace Ruby agent with another one to bypass 403 from Unity
  • Loading branch information
Paul Niezborala authored Jan 4, 2023
2 parents 6263c23 + 8e89fa0 commit 2708567
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/u3d/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ module Utils
# Regex to capture each part of a version string (0.0.0x0)
CSIDL_LOCAL_APPDATA = 0x001c
UNITY_VERSION_REGEX = /(\d+)(?:\.(\d+)(?:\.(\d+))?)?(?:(\w)(?:(\d+))?)?/.freeze
MOZILLA_AGENT_HEADER = {
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:106.0) Gecko/20100101 Firefox/106.0'
}.freeze

class << self
def final_url(url, redirect_limit: 10)
Expand All @@ -56,6 +59,9 @@ def page_content(url, redirect_limit: 10, request_headers: {})
def follow_redirects(url, redirect_limit: 10, http_method: :get, request_headers: {}, &block)
raise 'Too many redirections' if redirect_limit.zero?

# Unity blocks the default Ruby agent, use another one
request_headers = MOZILLA_AGENT_HEADER.merge(request_headers)

response = nil
request = nil
uri = URI(url)
Expand Down

0 comments on commit 2708567

Please sign in to comment.