mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[chore] NewsDownloader: remove custom redirect handling
It's been implemented in LuaSocket http.request() in the meantime.
This commit is contained in:
committed by
Frans de Jonge
parent
8b31f68462
commit
26d19c3c73
@@ -22,7 +22,6 @@ local EpubDownloadBackend = {
|
||||
-- accessible here so that caller can know it's a user dismiss.
|
||||
dismissed_error_code = "Interrupted by user",
|
||||
}
|
||||
local max_redirects = 5; --prevent infinite redirects
|
||||
|
||||
local FeedCache = CacheSQLite:new{
|
||||
slots = 500,
|
||||
@@ -158,19 +157,13 @@ local function build_cookies(cookies)
|
||||
end
|
||||
|
||||
-- Get URL content
|
||||
local function getUrlContent(url, cookies, timeout, maxtime, redirectCount, add_to_cache)
|
||||
logger.dbg("getUrlContent(", url, ",", cookies, ", ", timeout, ",", maxtime, ",", redirectCount, ",", add_to_cache, ")")
|
||||
if not redirectCount then
|
||||
redirectCount = 0
|
||||
elseif redirectCount == max_redirects then
|
||||
error("EpubDownloadBackend: reached max redirects: ", redirectCount)
|
||||
end
|
||||
local function getUrlContent(url, cookies, timeout, maxtime, add_to_cache)
|
||||
logger.dbg("getUrlContent(", url, ",", cookies, ", ", timeout, ",", maxtime, ",", add_to_cache, ")")
|
||||
|
||||
if not timeout then timeout = 10 end
|
||||
logger.dbg("timeout:", timeout)
|
||||
|
||||
local sink = {}
|
||||
local parsed = socket_url.parse(url)
|
||||
socketutil:set_timeout(timeout, maxtime or 30)
|
||||
local request = {
|
||||
url = url,
|
||||
@@ -207,23 +200,6 @@ local function getUrlContent(url, cookies, timeout, maxtime, redirectCount, add_
|
||||
logger.warn("No HTTP headers:", status or code or "network unreachable")
|
||||
return false, "Network or remote server unavailable"
|
||||
end
|
||||
if not code or code < 200 or code > 299 then -- all 200..299 HTTP codes are OK
|
||||
if code and code > 299 and code < 400 and headers and headers.location then -- handle 301, 302...
|
||||
local redirected_url = headers.location
|
||||
local parsed_redirect_location = socket_url.parse(redirected_url)
|
||||
if not parsed_redirect_location.host then
|
||||
parsed_redirect_location.host = parsed.host
|
||||
parsed_redirect_location.scheme = parsed.scheme
|
||||
redirected_url = socket_url.build(parsed_redirect_location)
|
||||
end
|
||||
logger.dbg("getUrlContent: Redirecting to url: ", redirected_url)
|
||||
return getUrlContent(redirected_url, timeout, maxtime, redirectCount + 1, add_to_cache)
|
||||
else
|
||||
error("EpubDownloadBackend: Don't know how to handle HTTP response status:", status or code)
|
||||
end
|
||||
logger.warn("HTTP status not okay:", status or code)
|
||||
return false, status or code
|
||||
end
|
||||
if headers and headers["content-length"] then
|
||||
-- Check we really got the announced content size
|
||||
local content_length = tonumber(headers["content-length"])
|
||||
@@ -281,7 +257,7 @@ end
|
||||
|
||||
function EpubDownloadBackend:getResponseAsString(url, cookies, add_to_cache)
|
||||
logger.dbg("EpubDownloadBackend:getResponseAsString(", url, ")")
|
||||
local success, content = getUrlContent(url, cookies, nil, nil, nil, add_to_cache)
|
||||
local success, content = getUrlContent(url, cookies, nil, nil, add_to_cache)
|
||||
if (success) then
|
||||
return content
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user