diff --git a/common/pom.xml b/common/pom.xml
index 8ec34d37..4f0a8c73 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -5,7 +5,7 @@
proxyee-down
lee.study
- 2.2
+ 2.21
4.0.0
diff --git a/core/pom.xml b/core/pom.xml
index 0005d137..f5817ed5 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -5,7 +5,7 @@
proxyee-down
lee.study
- 2.2
+ 2.21
4.0.0
diff --git a/pom.xml b/pom.xml
index 6af3c0d0..e69c1f2c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
lee.study
proxyee-down
- 2.2
+ 2.21
pom
diff --git a/sniff/pom.xml b/sniff/pom.xml
index 35effbd8..45f10ea4 100644
--- a/sniff/pom.xml
+++ b/sniff/pom.xml
@@ -5,7 +5,7 @@
proxyee-down
lee.study
- 2.2
+ 2.21
4.0.0
diff --git a/sniff/src/main/java/lee/study/down/intercept/HttpDownSniffIntercept.java b/sniff/src/main/java/lee/study/down/intercept/HttpDownSniffIntercept.java
index 88c84d01..290d47d9 100644
--- a/sniff/src/main/java/lee/study/down/intercept/HttpDownSniffIntercept.java
+++ b/sniff/src/main/java/lee/study/down/intercept/HttpDownSniffIntercept.java
@@ -62,22 +62,22 @@ public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpRespo
HttpHeaders httpResHeaders = httpResponse.headers();
String accept = pipeline.getHttpRequest().headers().get(HttpHeaderNames.ACCEPT);
String contentType = httpResHeaders.get(HttpHeaderNames.CONTENT_TYPE);
- if (accept != null
- && accept.matches("^.*text/html.*$") //直接url的方式访问不是以HTML标签加载的(a标签除外)
- && contentType != null
- && !contentType.matches("^.*text/.*$")) { //响应体不是text/html报文
- //有两种情况进行下载 1.url后缀为.xxx 2.带有CONTENT_DISPOSITION:ATTACHMENT响应头
- String disposition = httpResHeaders.get(HttpHeaderNames.CONTENT_DISPOSITION);
- if (pipeline.getHttpRequest().uri().matches("^.*\\.[^./]{1,5}(\\?[^?]*)?$")
- || (disposition != null && disposition.contains(HttpHeaderValues.ATTACHMENT))) {
- downFlag = true;
- }
+ //有两种情况进行下载 1.url后缀为.xxx 2.带有CONTENT_DISPOSITION:ATTACHMENT响应头
+ String disposition = httpResHeaders.get(HttpHeaderNames.CONTENT_DISPOSITION);
+ if ((disposition != null
+ && disposition.contains(HttpHeaderValues.ATTACHMENT)
+ && disposition.contains(HttpHeaderValues.FILENAME))
+ || (pipeline.getHttpRequest().uri().matches("^.*\\.[^./]{1,5}(\\?[^?]*)?$")
+ && isDownAccept(accept, contentType))) {
+ downFlag = true;
}
+
HttpRequestInfo httpRequestInfo = (HttpRequestInfo) pipeline.getHttpRequest();
if (downFlag) { //如果是下载
proxyChannel.close();//关闭嗅探下载连接
LOGGER.debug("=====================下载===========================\n" +
pipeline.getHttpRequest().toString() + "\n" +
+ "------------------------------------------------" +
httpResponse.toString() + "\n" +
"================================================");
//原始的请求协议
@@ -101,4 +101,28 @@ public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpConte
pipeline.afterResponse(clientChannel, proxyChannel, httpContent);
}
}
+
+ private boolean isDownAccept(String accepts, String contentType) {
+ if (accepts != null && accepts.matches("^.*text/html.*$")) {
+ String[] acceptArray = accepts.split(",");
+ String contentType0 = contentType.split(";")[0];
+ for (String accpet : acceptArray) {
+ if (accpet.equals("*/*") && contentType.matches("^(?i)application/x.*$")) {
+ return false;
+ } else {
+ String accpet0 = "^(?i)" + accpet.split(";")[0].replaceAll("\\*", ".*") + "$";
+ if (contentType0.matches(accpet0)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public static void main(String[] args) {
+ System.out.println(new HttpDownSniffIntercept().isDownAccept("*/*", "image/gif"));
+ }
}
diff --git a/ui/pom.xml b/ui/pom.xml
index b0cdc118..bae1e12e 100644
--- a/ui/pom.xml
+++ b/ui/pom.xml
@@ -5,7 +5,7 @@
proxyee-down
lee.study
- 2.2
+ 2.21
4.0.0
diff --git a/ui/src/main/java/lee/study/down/content/ConfigContent.java b/ui/src/main/java/lee/study/down/content/ConfigContent.java
index 525d022e..846423f6 100644
--- a/ui/src/main/java/lee/study/down/content/ConfigContent.java
+++ b/ui/src/main/java/lee/study/down/content/ConfigContent.java
@@ -42,7 +42,7 @@ public void init() {
LOGGER.error("加载配置文件失败:", e);
}
}
- if (configContent == null) {
+ if (configContent == null || configContent.getProxyPort() == 0) {
configContent = new ConfigInfo();
//默认代理端口
configContent.setProxyPort(9999);
@@ -52,15 +52,10 @@ public void init() {
configContent.setTimeout(30);
//默认百度云嗅探模式
configContent.setSniffModel(2);
+ //默认GUI模式
+ configContent.setUiModel(1);
//默认重试次数
configContent.setRetryCount(5);
- //安装证书
- try {
- WindowsUtil.installCert(
- Thread.currentThread().getContextClassLoader().getResourceAsStream("ca.crt"));
- } catch (IOException e) {
- LOGGER.error("install cert error:", e);
- }
save();
}
}
diff --git a/ui/src/main/java/lee/study/down/dispatch/HttpDownHandleCallback.java b/ui/src/main/java/lee/study/down/dispatch/HttpDownHandleCallback.java
index f742f6fe..f162cfb0 100644
--- a/ui/src/main/java/lee/study/down/dispatch/HttpDownHandleCallback.java
+++ b/ui/src/main/java/lee/study/down/dispatch/HttpDownHandleCallback.java
@@ -25,12 +25,10 @@ public void onStart(HttpDownInfo httpDownInfo) throws Exception {
@Override
public void onChunkConnecting(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo) throws Exception {
- sendTask(httpDownInfo.getTaskInfo().getId());
}
@Override
public void onChunkConnected(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo) throws Exception {
- sendTask(httpDownInfo.getTaskInfo().getId());
}
@Override
@@ -56,13 +54,11 @@ public void onError(HttpDownInfo httpDownInfo, Throwable cause) {
@Override
public void onChunkError(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo, Throwable cause) {
- sendTask(httpDownInfo.getTaskInfo().getId());
}
@Override
public void onChunkDone(HttpDownInfo httpDownInfo, ChunkInfo chunkInfo) {
ContentManager.DOWN.saveTask(httpDownInfo.getTaskInfo().getId());
- sendTask(httpDownInfo.getTaskInfo().getId());
}
@Override
diff --git a/ui/src/main/java/lee/study/down/gui/HttpDownApplication.java b/ui/src/main/java/lee/study/down/gui/HttpDownApplication.java
index 64a05c3e..b7833402 100644
--- a/ui/src/main/java/lee/study/down/gui/HttpDownApplication.java
+++ b/ui/src/main/java/lee/study/down/gui/HttpDownApplication.java
@@ -8,7 +8,6 @@
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
-import java.io.IOException;
import java.net.URL;
import java.util.List;
import javafx.application.Application;
@@ -55,6 +54,8 @@ public class HttpDownApplication extends Application {
System.setProperty("LOG_PATH", PathUtil.ROOT_PATH);
//netty设置为堆内存分配
System.setProperty("io.netty.noPreferDirect", "true");
+ //不使用内存池
+ System.setProperty("io.netty.allocator.numHeapArenas","0");
}
private void initConfig() throws Exception {
@@ -91,10 +92,8 @@ private void initHandle() throws Exception {
private void beforeOpen() throws Exception {
//webview加载
- if (Boolean.valueOf(ConfigUtil.getValue("javafx.model"))) {
- this.browser = new Browser();
- stage.setScene(new Scene(browser));
- browser.load(this.url);
+ if (ContentManager.CONFIG.get().getUiModel() == 1) {
+ initBrowser();
}
//证书安装引导
@@ -147,7 +146,6 @@ public void start(Stage stage) throws Exception {
Platform.setImplicitExit(false);
SwingUtilities.invokeLater(this::addTray);
stage.setTitle("proxyee-down-" + version);
- stage.setResizable(false);
Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
stage.setX(primaryScreenBounds.getMinX());
stage.setY(primaryScreenBounds.getMinY());
@@ -160,12 +158,12 @@ public void start(Stage stage) throws Exception {
close();
});
beforeOpen();
- open();
+// open();
afterOpen();
}
public void open() {
- if (browser == null) {
+ if (browser == null || ContentManager.CONFIG.get().getUiModel() == 2) {
try {
OsUtil.openBrowse(url);
} catch (Exception e) {
@@ -274,6 +272,38 @@ private void addTray() {
});
}
+ Menu uiMenu = new Menu("UI模式");
+ CheckboxMenuItemGroup mig = new CheckboxMenuItemGroup();
+ CheckboxMenuItem guiItem = new CheckboxMenuItem("GUI");
+ guiItem.setName("1");
+ CheckboxMenuItem browserItem = new CheckboxMenuItem("浏览器");
+ browserItem.setName("2");
+ uiMenu.add(guiItem);
+ uiMenu.add(browserItem);
+ mig.add(guiItem);
+ mig.add(browserItem);
+ //默认选中
+ if (ContentManager.CONFIG.get().getUiModel() == 1) {
+ mig.selectItem(guiItem);
+ } else {
+ mig.selectItem(browserItem);
+ }
+ mig.addActionListener(event -> {
+ String selectedItemName = ((CheckboxMenuItem) event.getSource()).getName();
+ Platform.runLater(() -> {
+ if ("1".equals(selectedItemName)) {
+ initBrowser();
+ ContentManager.CONFIG.get().setUiModel(1);
+ } else {
+ destroyBrowser();
+ stage.close();
+ ContentManager.CONFIG.get().setUiModel(2);
+ }
+ open();
+ ContentManager.CONFIG.save();
+ });
+ });
+
MenuItem aboutItem = new MenuItem("关于");
aboutItem.addActionListener(event -> Platform.runLater(() -> {
if (browser != null) {
@@ -289,6 +319,7 @@ private void addTray() {
popupMenu.addSeparator();
popupMenu.add(crtItem);
popupMenu.add(proxyMenu);
+ popupMenu.add(uiMenu);
popupMenu.addSeparator();
popupMenu.add(aboutItem);
popupMenu.add(closeItem);
@@ -302,6 +333,20 @@ private void addTray() {
}
}
+ private void initBrowser() {
+ if (this.browser == null) {
+ this.browser = new Browser();
+ stage.setScene(new Scene(browser));
+ }
+ browser.load(this.url);
+ }
+
+ private void destroyBrowser() {
+ if (this.browser != null) {
+ browser.load(null);
+ }
+ }
+
public static HttpDownProxyServer getProxyServer() {
return proxyServer;
}
diff --git a/ui/src/main/java/lee/study/down/intercept/HttpDownHandleInterceptFactory.java b/ui/src/main/java/lee/study/down/intercept/HttpDownHandleInterceptFactory.java
index 14fb1cb2..400c3730 100644
--- a/ui/src/main/java/lee/study/down/intercept/HttpDownHandleInterceptFactory.java
+++ b/ui/src/main/java/lee/study/down/intercept/HttpDownHandleInterceptFactory.java
@@ -43,12 +43,7 @@ public void afterResponse(Channel clientChannel, Channel proxyChannel,
httpResponse.setStatus(HttpResponseStatus.OK);
httpResponse.headers().clear();
httpResponse.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html;charset=utf-8");
- byte[] content = (
- ""
- + ""
- + ""
- + ""
- + "")
+ byte[] content = ("")
.getBytes("utf-8");
httpResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, content.length);
clientChannel.writeAndFlush(httpResponse);
diff --git a/ui/src/main/java/lee/study/down/model/ConfigBaseInfo.java b/ui/src/main/java/lee/study/down/model/ConfigBaseInfo.java
index de15aa59..9a10bc25 100644
--- a/ui/src/main/java/lee/study/down/model/ConfigBaseInfo.java
+++ b/ui/src/main/java/lee/study/down/model/ConfigBaseInfo.java
@@ -9,6 +9,7 @@ public class ConfigBaseInfo implements Serializable {
private int proxyPort; //代理端口号
private int sniffModel; //嗅探模式 1.全局 2.百度云 3.关闭
+ private int uiModel; //嗅探模式 1.GUI 2.浏览器
private int connections; //默认分段数
private int timeout; //超时重试时间
private boolean secProxyEnable; //二级代理开关
diff --git a/ui/src/main/resources/application-dev.properties b/ui/src/main/resources/application-dev.properties
index 071e8904..81ce3417 100644
--- a/ui/src/main/resources/application-dev.properties
+++ b/ui/src/main/resources/application-dev.properties
@@ -1,6 +1,5 @@
spring.resources.static-locations=classpath:/pac/
logging.config=classpath:logback-dev.xml
-javafx.model=false
#server.port= 8443
#server.ssl.key-store=classpath:server.p12
#server.ssl.key-store-password= 123456
\ No newline at end of file
diff --git a/ui/src/main/resources/application-prd.properties b/ui/src/main/resources/application-prd.properties
index a89c32dd..5ee292ee 100644
--- a/ui/src/main/resources/application-prd.properties
+++ b/ui/src/main/resources/application-prd.properties
@@ -1,7 +1,6 @@
spring.resources.static-locations=classpath:/pac/,classpath:/view/
spring.resources.cache-period=0
logging.config=classpath:logback-prd.xml
-javafx.model=true
#server.port= 8443
#server.ssl.key-store=classpath:server.p12
#server.ssl.key-store-password= 123456
\ No newline at end of file
diff --git a/ui/src/main/resources/application.properties b/ui/src/main/resources/application.properties
index 87ddfd87..b126d9b1 100644
--- a/ui/src/main/resources/application.properties
+++ b/ui/src/main/resources/application.properties
@@ -1,4 +1,4 @@
-app.version=2.2
+app.version=2.21
spring.profiles.active=prd
view.server.port = 8999
tomcat.server.port = 9000
diff --git a/ui/src/main/resources/res/pd.pac b/ui/src/main/resources/res/pd.pac
index 27bf6c1c..9e49a185 100644
--- a/ui/src/main/resources/res/pd.pac
+++ b/ui/src/main/resources/res/pd.pac
@@ -1,15 +1,20 @@
function FindProxyForURL(url, host) {
+ if (isInNet(host, '127.0.0.1', '255.0.0.255')
+ || isInNet(dnsResolve(host), '127.0.0.1', '255.0.0.255')) {
+ return 'DIRECT';
+ }
var regs = [
- '^https://(pan|yun).baidu.com.*$',
- '^https://.*.baidupcs.com/file/.*$',
- '^https://.*.baidupcs.com/rest/.*/pcs/file.*$',
+ 'pan.baidu.com',
+ 'yun.baidu.com',
+ '*.baidupcs.com',
];
var match = false;
for (var i = 0; i < regs.length; i++) {
- if (url.match(regs[i])) {
+ if (shExpMatch(host, regs[i])) {
match = true;
break;
}
}
- return match ? "PROXY 127.0.0.1:{port}" : "DIRECT";
+ return match ? 'PROXY 127.0.0.1:{port}' : 'DIRECT';
+
}
\ No newline at end of file
diff --git a/update/pom.xml b/update/pom.xml
index 021d72e1..5f737373 100644
--- a/update/pom.xml
+++ b/update/pom.xml
@@ -7,7 +7,7 @@
lee.study
proxyee-down-update
jar
- 2.2
+ 2.21
UTF-8