Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] U3d::Utils: replace Ruby agent with another one to bypass 403 from Unity #434

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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