fix: Wikipedia 429 due to incorrect user agent (#14981)

Wikipedia recently started enforcing user agents to contain a contact
link. Without a contact, the request is subject to 429 errors when
requesting images.
This commit is contained in:
oscargolding authored and GitHub committed 2026-02-17 08:23:31 +01:00
1 parent 06b3a4e5b1
commit d8fc84240e
1 file changed
+5 -2
+5 -2
View File
@@ -8,6 +8,8 @@ local http = require("socket.http")
local https = require("ssl.https")
local ltn12 = require("ltn12")
local socket = require("socket")
local ffiUtil = require("ffi/util")
local T = ffiUtil.template
local socketutil = {
-- Init to the default LuaSocket/LuaSec values
@@ -15,9 +17,10 @@ local socketutil = {
total_timeout = -1,
}
--- Builds a sensible UserAgent that fits Wikipedia's UA policy <https://meta.wikimedia.org/wiki/User-Agent_policy>
--- Builds a sensible UserAgent that fits Wikipedia's UA policy <https://foundation.wikimedia.org/wiki/Policy:Wikimedia_Foundation_User-Agent_Policy>
local socket_ua = http.USERAGENT
socketutil.USER_AGENT = "KOReader/" .. Version:getShortVersion() .. " (" .. Device.model .. "; " .. jit.os .. "; " .. jit.arch .. ") " .. socket_ua:gsub(" ", "/")
socketutil.USER_AGENT = T("KOReader/%1 (%2; %3; %4; https://github.com/koreader/koreader) %5",
Version:getShortVersion(), Device.model, jit.os, jit.arch, socket_ua:gsub(" ", "/"))
-- Monkey-patch it in LuaSocket, as it already takes care of inserting the appropriate header to its requests.
http.USERAGENT = socketutil.USER_AGENT