Explorar el Código

header中没有Content-Disposition,则从url中获取文件名 (#251)

需要对合并后的代码进行越界判断处理
Drew hace 3 años
padre
commit
19cf958e03
Se han modificado 1 ficheros con 2 adiciones y 1 borrados
  1. 2 1
      internal/pkg/my_util/util.go

+ 2 - 1
internal/pkg/my_util/util.go

@@ -117,7 +117,8 @@ func DownFile(l *logrus.Logger, urlStr string, _proxySettings ...*settings.Proxy
 func GetFileName(l *logrus.Logger, resp *http.Response) string {
 	contentDisposition := resp.Header.Get("Content-Disposition")
 	if len(contentDisposition) == 0 {
-		return ""
+		m := regexp.MustCompile(`^(.*/)?(?:$|(.+?)(?:(\.[^.]*$)|$))`).FindStringSubmatch(resp.Request.URL.String())
+		return m[2]+m[3]
 	}
 	re := regexp.MustCompile(`filename=["]*([^"]+)["]*`)
 	matched := re.FindStringSubmatch(contentDisposition)