现在http文件下载将使用HEAD请求获取文件大小,配置文件增加 <useHeadRequest value=false/>

pull/789/head
laoyuyu 4 years ago
parent 9d8bf579b6
commit 5f60b9ed57
  1. 15
      Aria/src/main/java/com/arialyy/aria/core/Aria.java
  2. 1
      DEV_LOG.md
  3. 8
      HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDFileInfoTask.java
  4. 18
      PublicComponent/src/main/java/com/arialyy/aria/core/config/DGroupConfig.java
  5. 15
      PublicComponent/src/main/java/com/arialyy/aria/core/config/DownloadConfig.java
  6. 6
      PublicComponent/src/main/java/com/arialyy/aria/core/config/XMLReader.java
  7. 4
      app/src/main/assets/aria_config.xml
  8. 2
      app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
  9. 4
      app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.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)");

@ -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请求获取文件大小,配置文件增加 <useHeadRequest value="false"/>
+ 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

@ -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);

@ -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;
}

@ -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;
}

@ -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");

@ -21,6 +21,10 @@
<!--普通下载任务-->
<download>
<!--设置http下载获取文件大小是否使用Head请求。true:使用head请求,false:使用默认的get请求-->
<!--只适用于3.8.11以上的版本-->
<useHeadRequest value="true"/>
<!--设置任务最大下载速度,0表示不限速,单位为:kb-->
<maxSpeed value="128"/>

@ -364,7 +364,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
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;
}

@ -55,7 +55,9 @@ public class HttpUploadActivity extends BaseActivity<ActivitySingleBinding> {
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() {

Loading…
Cancel
Save