Add cookie to torrent request
This commit is contained in:
1 parent
92f716170c
commit
6a9e0198a2
2 files changed
+15
No files matched your search
@@ -116,6 +116,7 @@ import java.io.OutputStream;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.List;
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
public class GalleryDetailScene extends BaseScene implements View.OnClickListener,
|
||||
com.hippo.ehviewer.download.DownloadManager.DownloadInfoListener,
|
||||
@@ -1875,6 +1876,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
FileUtils.sanitizeFilename(name + ".torrent"));
|
||||
r.allowScanningByMediaScanner();
|
||||
r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
r.addRequestHeader("Cookie", EhApplication.getEhCookieStore(context).getCookieHeader(HttpUrl.get(url)));
|
||||
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
if (dm != null) {
|
||||
try {
|
||||
|
||||
@@ -85,6 +85,19 @@ public class CookieRepository implements CookieJar {
|
||||
}
|
||||
}
|
||||
|
||||
public String getCookieHeader(HttpUrl url) {
|
||||
List<Cookie> cookies = getCookies(url);
|
||||
StringBuilder cookieHeader = new StringBuilder();
|
||||
for (int i = 0, size = cookies.size(); i < size; i++) {
|
||||
if (i > 0) {
|
||||
cookieHeader.append("; ");
|
||||
}
|
||||
Cookie cookie = cookies.get(i);
|
||||
cookieHeader.append(cookie.name()).append('=').append(cookie.value());
|
||||
}
|
||||
return cookieHeader.toString();
|
||||
}
|
||||
|
||||
public synchronized List<Cookie> getCookies(HttpUrl url) {
|
||||
List<Cookie> accepted = new ArrayList<>();
|
||||
List<Cookie> expired = new ArrayList<>();
|
||||
|
||||
Reference in new issue
Block a user