From 5f60b9ed57496679d19ffcf3e6fdb969f08298a2 Mon Sep 17 00:00:00 2001
From: laoyuyu <511455842@qq.com>
Date: Mon, 27 Jul 2020 20:21:15 +0800
Subject: [PATCH] =?UTF-8?q?=E7=8E=B0=E5=9C=A8http=E6=96=87=E4=BB=B6?=
=?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=B0=86=E4=BD=BF=E7=94=A8HEAD=E8=AF=B7?=
=?UTF-8?q?=E6=B1=82=E8=8E=B7=E5=8F=96=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F?=
=?UTF-8?q?=EF=BC=8C=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=20?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../main/java/com/arialyy/aria/core/Aria.java | 15 ++++++++++-----
DEV_LOG.md | 1 +
.../aria/http/download/HttpDFileInfoTask.java | 8 ++++++++
.../arialyy/aria/core/config/DGroupConfig.java | 18 ++----------------
.../aria/core/config/DownloadConfig.java | 15 +++++++++++++++
.../arialyy/aria/core/config/XMLReader.java | 6 +++++-
app/src/main/assets/aria_config.xml | 4 ++++
.../download/m3u8/M3U8VodDLoadActivity.java | 2 +-
.../simple/core/upload/HttpUploadActivity.java | 4 +++-
9 files changed, 49 insertions(+), 24 deletions(-)
diff --git a/Aria/src/main/java/com/arialyy/aria/core/Aria.java b/Aria/src/main/java/com/arialyy/aria/core/Aria.java
index b68d0c38..ed27fb18 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/Aria.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/Aria.java
@@ -131,15 +131,20 @@ import com.arialyy.aria.util.CommonUtil;
private static Context convertContext(Object obj) {
if (obj instanceof Application) {
return (Application) obj;
- } else if (obj instanceof Service) {
+ }
+ if (obj instanceof Service) {
return (Service) obj;
- } else if (obj instanceof Activity) {
+ }
+ if (obj instanceof Activity) {
return (Activity) obj;
- } else if (CommonUtil.isFragment(obj.getClass())) {
+ }
+ if (CommonUtil.isFragment(obj.getClass())) {
return CommonUtil.getFragmentActivity(obj);
- } else if (obj instanceof Dialog) {
+ }
+ if (obj instanceof Dialog) {
return ((Dialog) obj).getContext();
- } else if (obj instanceof PopupWindow) {
+ }
+ if (obj instanceof PopupWindow) {
return ((PopupWindow) obj).getContentView().getContext();
}
ALog.e("Aria", "请使用download(this)或upload(this)");
diff --git a/DEV_LOG.md b/DEV_LOG.md
index 2e77da7d..8dfaba43 100644
--- a/DEV_LOG.md
+++ b/DEV_LOG.md
@@ -3,6 +3,7 @@
- 修复一个正则表达式导致的文件名保存号异常问题 https://github.com/AriaLyy/Aria/issues/715
- 修复一个匿名内部类中的内存溢出的问题 https://github.com/AriaLyy/Aria/issues/705
- m3u8密钥下载地址转换器增加ts列表的url地址 https://github.com/AriaLyy/Aria/issues/718
+ - 现在http文件下载将使用HEAD请求获取文件大小,配置文件增加
+ v_3.8.10 (2020/6/26)
- fix bug https://github.com/AriaLyy/Aria/issues/703
- fix bug https://github.com/AriaLyy/Aria/issues/702
diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDFileInfoTask.java b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDFileInfoTask.java
index 9834c217..c63e4f52 100644
--- a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDFileInfoTask.java
+++ b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDFileInfoTask.java
@@ -19,6 +19,7 @@ import android.net.TrafficStats;
import android.net.Uri;
import android.os.Process;
import android.text.TextUtils;
+import android.util.Log;
import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.common.CompleteInfo;
import com.arialyy.aria.core.common.RequestEnum;
@@ -80,6 +81,10 @@ final class HttpDFileInfoTask implements IInfoTask, Runnable {
conn = ConnectionHelp.handleConnection(url, taskOption);
ConnectionHelp.setConnectParam(taskOption, conn);
conn.setRequestProperty("Range", "bytes=" + 0 + "-");
+ if (AriaConfig.getInstance().getDConfig().isUseHeadRequest()){
+ ALog.d(TAG, "head请求");
+ conn.setRequestMethod("HEAD");
+ }
conn.setConnectTimeout(mConnectTimeOut);
conn.connect();
handleConnect(conn);
@@ -333,6 +338,9 @@ final class HttpDFileInfoTask implements IInfoTask, Runnable {
ConnectionHelp.setConnectParam(taskOption, conn);
conn.setRequestProperty("Cookie", cookies);
conn.setRequestProperty("Range", "bytes=" + 0 + "-");
+ if (AriaConfig.getInstance().getDConfig().isUseHeadRequest()){
+ conn.setRequestMethod("HEAD");
+ }
conn.setConnectTimeout(mConnectTimeOut);
conn.connect();
handleConnect(conn);
diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/config/DGroupConfig.java b/PublicComponent/src/main/java/com/arialyy/aria/core/config/DGroupConfig.java
index c99ab3e9..0dc6a033 100644
--- a/PublicComponent/src/main/java/com/arialyy/aria/core/config/DGroupConfig.java
+++ b/PublicComponent/src/main/java/com/arialyy/aria/core/config/DGroupConfig.java
@@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.config;
+import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.event.DGMaxNumEvent;
import com.arialyy.aria.core.event.DSpeedEvent;
import com.arialyy.aria.core.event.EventMsgUtil;
@@ -63,22 +64,7 @@ public class DGroupConfig extends BaseTaskConfig implements Serializable {
}
public DownloadConfig getSubConfig() {
- if (subConfig == null) {
- subConfig = new DownloadConfig();
- subConfig.threadNum = 1;
- subConfig.useBlock = false;
- subConfig.buffSize = buffSize;
- subConfig.caName = caName;
- subConfig.caPath = caPath;
- subConfig.connectTimeOut = connectTimeOut;
- subConfig.iOTimeOut = iOTimeOut;
- subConfig.isConvertSpeed = isConvertSpeed;
- subConfig.maxSpeed = maxSpeed;
- subConfig.queueMod = "now";
- subConfig.reTryInterval = subReTryInterval;
- subConfig.reTryNum = subReTryNum;
- subConfig.updateInterval = updateInterval;
- }
+ subConfig = AriaConfig.getInstance().getDConfig();
return subConfig;
}
diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/config/DownloadConfig.java b/PublicComponent/src/main/java/com/arialyy/aria/core/config/DownloadConfig.java
index 21114cce..fc63dbeb 100644
--- a/PublicComponent/src/main/java/com/arialyy/aria/core/config/DownloadConfig.java
+++ b/PublicComponent/src/main/java/com/arialyy/aria/core/config/DownloadConfig.java
@@ -44,6 +44,21 @@ public class DownloadConfig extends BaseTaskConfig implements Serializable {
*/
boolean useBlock = true;
+ /**
+ * 设置http下载获取文件大小是否使用Head请求。true:使用head请求,false:使用默认的get请求
+ */
+ boolean useHeadRequest;
+
+ public boolean isUseHeadRequest() {
+ return useHeadRequest;
+ }
+
+ public DownloadConfig setUseHeadRequest(boolean useHeadRequest) {
+ this.useHeadRequest = useHeadRequest;
+ save();
+ return this;
+ }
+
public boolean isUseBlock() {
return useBlock;
}
diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/config/XMLReader.java b/PublicComponent/src/main/java/com/arialyy/aria/core/config/XMLReader.java
index 0e25c6f1..e4859256 100644
--- a/PublicComponent/src/main/java/com/arialyy/aria/core/config/XMLReader.java
+++ b/PublicComponent/src/main/java/com/arialyy/aria/core/config/XMLReader.java
@@ -146,7 +146,7 @@ public class XMLReader extends DefaultHandler {
break;
case "subFailAsStop": // 子任务失败时回调stop
setField("subFailAsStop", checkBoolean(value) ? Boolean.valueOf(value) : false,
- ConfigType.D_GROUP);
+ ConfigType.D_GROUP);
break;
case "subReTryNum": // 子任务重试次数
int subReTryNum = checkInt(value) ? Integer.parseInt(value) : 5;
@@ -156,6 +156,10 @@ public class XMLReader extends DefaultHandler {
int subReTryInterval = checkInt(value) ? Integer.parseInt(value) : 2000;
setField("subReTryInterval", subReTryInterval, ConfigType.D_GROUP);
break;
+ case "useHeadRequest": // 是否使用head请求
+ boolean useHeadRequest = checkBoolean(value) ? Boolean.valueOf(value) : true;
+ setField("useHeadRequest", useHeadRequest, ConfigType.DOWNLOAD);
+ break;
}
} else if (mType == ConfigType.APP) {
String value = attributes.getValue("value");
diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml
index 26922e63..ea5b0bfa 100644
--- a/app/src/main/assets/aria_config.xml
+++ b/app/src/main/assets/aria_config.xml
@@ -21,6 +21,10 @@
+
+
+
+
diff --git a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
index 37567992..4e778dd0 100644
--- a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
+++ b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
@@ -364,7 +364,7 @@ public class M3U8VodDLoadActivity extends BaseActivity {
static class KeyUrlConverter implements IKeyUrlConverter {
- @Override public String convert(String m3u8Url, String keyUrl) {
+ @Override public String convert(String m3u8Url, String tsListUrl, String keyUrl) {
ALog.d("TAG", "convertUrl....");
return null;
}
diff --git a/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java b/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java
index 76fee636..f195346a 100644
--- a/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java
+++ b/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java
@@ -55,7 +55,9 @@ public class HttpUploadActivity extends BaseActivity {
Aria.upload(this).getTaskList();
mEntity = Aria.upload(this).getFirstUploadEntity(FILE_PATH);
- getBinding().pl.setInfo(mEntity);
+ if (mEntity != null){
+ getBinding().pl.setInfo(mEntity);
+ }
Aria.upload(this).register();
getBinding().pl.setBtListener(new ProgressLayout.OnProgressLayoutBtListener() {