user agent
This commit is contained in:
@@ -60,7 +60,10 @@ static func load_web_font(font_info: Dictionary) -> void:
|
|||||||
temp_parent.queue_free()
|
temp_parent.queue_free()
|
||||||
)
|
)
|
||||||
|
|
||||||
http_request.request(src)
|
var headers = PackedStringArray()
|
||||||
|
headers.append("User-Agent: " + UserAgent.get_user_agent())
|
||||||
|
|
||||||
|
http_request.request(src, headers)
|
||||||
|
|
||||||
static func get_font(family_name: String) -> Font:
|
static func get_font(family_name: String) -> Font:
|
||||||
if family_name == "sans-serif":
|
if family_name == "sans-serif":
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ func fetch_image(url: String) -> ImageTexture:
|
|||||||
if url.is_empty():
|
if url.is_empty():
|
||||||
return null
|
return null
|
||||||
|
|
||||||
var error = http_request.request(url)
|
var request_headers = PackedStringArray()
|
||||||
|
request_headers.append("User-Agent: " + UserAgent.get_user_agent())
|
||||||
|
|
||||||
|
var error = http_request.request(url, request_headers)
|
||||||
if error != OK:
|
if error != OK:
|
||||||
print("Error making HTTP request: ", error)
|
print("Error making HTTP request: ", error)
|
||||||
http_request.queue_free()
|
http_request.queue_free()
|
||||||
|
|||||||
@@ -35,4 +35,4 @@ func load_image_async(src: String, element: HTMLParser.HTMLElement, parser: HTML
|
|||||||
custom_minimum_size = Vector2.ZERO
|
custom_minimum_size = Vector2.ZERO
|
||||||
else:
|
else:
|
||||||
custom_minimum_size = Vector2(1, 1)
|
custom_minimum_size = Vector2(1, 1)
|
||||||
size = Vector2(100, 100) # StyleManager will handle this
|
size = Vector2(100, 100) # StyleManager will handle this
|
||||||
|
|||||||
@@ -19,9 +19,16 @@ static func _lua_fetch_handler(vm: LuauVM) -> int:
|
|||||||
|
|
||||||
# Set request options
|
# Set request options
|
||||||
var headers_array: PackedStringArray = []
|
var headers_array: PackedStringArray = []
|
||||||
|
|
||||||
|
var has_user_agent = false
|
||||||
for header_name in headers:
|
for header_name in headers:
|
||||||
|
if str(header_name).to_lower() == "user-agent":
|
||||||
|
has_user_agent = true
|
||||||
headers_array.append(str(header_name) + ": " + str(headers[header_name]))
|
headers_array.append(str(header_name) + ": " + str(headers[header_name]))
|
||||||
|
|
||||||
|
if not has_user_agent:
|
||||||
|
headers_array.append("User-Agent: " + UserAgent.get_user_agent())
|
||||||
|
|
||||||
var response_data = make_http_request(url, method, headers_array, body)
|
var response_data = make_http_request(url, method, headers_array, body)
|
||||||
|
|
||||||
# Create response object with actual data
|
# Create response object with actual data
|
||||||
|
|||||||
36
flumi/Scripts/Utils/UserAgent.gd
Normal file
36
flumi/Scripts/Utils/UserAgent.gd
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
class_name UserAgent
|
||||||
|
extends RefCounted
|
||||||
|
|
||||||
|
# Generate Flumi browser user agent string
|
||||||
|
static func get_user_agent() -> String:
|
||||||
|
var app_version = ProjectSettings.get_setting("application/config/version", "1.0.0")
|
||||||
|
var godot_version = Engine.get_version_info()
|
||||||
|
var os_name = OS.get_name()
|
||||||
|
|
||||||
|
var arch = ""
|
||||||
|
match os_name:
|
||||||
|
"Windows":
|
||||||
|
if OS.has_environment("PROCESSOR_ARCHITEW6432"):
|
||||||
|
arch = "x64"
|
||||||
|
elif OS.get_environment("PROCESSOR_ARCHITECTURE") == "AMD64":
|
||||||
|
arch = "x64"
|
||||||
|
else:
|
||||||
|
arch = "x86"
|
||||||
|
"Linux":
|
||||||
|
arch = "X11"
|
||||||
|
"macOS":
|
||||||
|
arch = "Intel"
|
||||||
|
_:
|
||||||
|
arch = "Unknown"
|
||||||
|
|
||||||
|
var user_agent = "Mozilla/5.0 (%s; %s) Flumi/%s GurtKit/%s Godot/%s.%s.%s (gurted.com)" % [
|
||||||
|
os_name,
|
||||||
|
arch,
|
||||||
|
app_version,
|
||||||
|
app_version,
|
||||||
|
godot_version.major,
|
||||||
|
godot_version.minor,
|
||||||
|
godot_version.patch
|
||||||
|
]
|
||||||
|
print(user_agent)
|
||||||
|
return user_agent
|
||||||
1
flumi/Scripts/Utils/UserAgent.gd.uid
Normal file
1
flumi/Scripts/Utils/UserAgent.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://v5m04vgylwbi
|
||||||
@@ -11,6 +11,7 @@ config_version=5
|
|||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="Flumi"
|
config/name="Flumi"
|
||||||
|
config/version="1.0.0"
|
||||||
run/main_scene="uid://bytm7bt2s4ak8"
|
run/main_scene="uid://bytm7bt2s4ak8"
|
||||||
config/features=PackedStringArray("4.4", "Forward Plus")
|
config/features=PackedStringArray("4.4", "Forward Plus")
|
||||||
config/icon="uid://ctpe0lbehepen"
|
config/icon="uid://ctpe0lbehepen"
|
||||||
|
|||||||
Reference in New Issue
Block a user