From f6e561923cddcd7133ad0103e9f06c7240f254b4 Mon Sep 17 00:00:00 2001 From: Sergey Avseyev Date: Wed, 8 May 2019 13:41:04 +0300 Subject: [PATCH] newsdownloader: rebuild URL on redirect to bare path (#5012) The server might redirect to only path, in this case the scheme and host should be taken from original URL --- plugins/newsdownloader.koplugin/epubdownloadbackend.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/newsdownloader.koplugin/epubdownloadbackend.lua b/plugins/newsdownloader.koplugin/epubdownloadbackend.lua index 42814384d..e8bd2e5fd 100644 --- a/plugins/newsdownloader.koplugin/epubdownloadbackend.lua +++ b/plugins/newsdownloader.koplugin/epubdownloadbackend.lua @@ -104,6 +104,12 @@ local function getUrlContent(url, timeout, maxtime, redirectCount) if not code or string.sub(code, 1, 1) ~= "2" 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) else