lib/downloader.rb in narou-2.8.1 vs lib/downloader.rb in narou-2.8.2

- old
+ new

@@ -707,11 +707,12 @@ def get_toc_source toc_url = @setting["toc_url"] return nil unless toc_url toc_source = "" cookie = @setting["cookie"] || "" - open(toc_url, "Cookie" => cookie) do |toc_fp| + open_uri_options = make_open_uri_options("Cookie" => cookie, allow_redirections: :safe) + open(toc_url, open_uri_options) do |toc_fp| if toc_fp.base_uri.to_s != toc_url # リダイレクトされた場合。 # ノクターン・ムーンライトのNコードを ncode.syosetu.com に渡すと、novel18.syosetu.com に飛ばされる # 目次の定義が微妙に ncode.syosetu.com と違うので、設定を取得し直す s = Downloader.get_sitesetting_by_target(toc_fp.base_uri.to_s) @@ -1087,10 +1088,11 @@ def download_raw_data(url) raw = nil retry_count = RETRY_MAX_FOR_503 cookie = @setting["cookie"] || "" begin - open(url, "Cookie" => cookie) do |fp| + open_uri_options = make_open_uri_options("Cookie" => cookie, allow_redirections: :safe) + open(url, open_uri_options) do |fp| raw = Helper.pretreatment_source(fp.read, @setting["encoding"]) end rescue OpenURI::HTTPError => e if e.message =~ /^503/ if retry_count == 0