Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
update to 2.21
Browse files Browse the repository at this point in the history
可以设置UI模式为gui或浏览器
gui模式下,窗口可以调整大小
修复非IE浏览器下百度云嗅探模式不生效问
修复下载速度快速跳动问题
禁用netty内存池
  • Loading branch information
monkeyWie committed Feb 7, 2018
1 parent 4dc7444 commit 6c914a1
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 50 deletions.
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>proxyee-down</artifactId>
<groupId>lee.study</groupId>
<version>2.2</version>
<version>2.21</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>proxyee-down</artifactId>
<groupId>lee.study</groupId>
<version>2.2</version>
<version>2.21</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>lee.study</groupId>
<artifactId>proxyee-down</artifactId>
<version>2.2</version>
<version>2.21</version>
<packaging>pom</packaging>

<modules>
Expand Down
2 changes: 1 addition & 1 deletion sniff/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>proxyee-down</artifactId>
<groupId>lee.study</groupId>
<version>2.2</version>
<version>2.21</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
"================================================");
//原始的请求协议
Expand All @@ -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"));
}
}
2 changes: 1 addition & 1 deletion ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>proxyee-down</artifactId>
<groupId>lee.study</groupId>
<version>2.2</version>
<version>2.21</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
11 changes: 3 additions & 8 deletions ui/src/main/java/lee/study/down/content/ConfigContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
61 changes: 53 additions & 8 deletions ui/src/main/java/lee/study/down/gui/HttpDownApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}

//证书安装引导
Expand Down Expand Up @@ -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());
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
"<html>"
+ "<head>"
+ "<script type=\"text/javascript\">window.history.back();</script>"
+ "</head>"
+ "</html>")
byte[] content = ("<html></html>")
.getBytes("utf-8");
httpResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, content.length);
clientChannel.writeAndFlush(httpResponse);
Expand Down
1 change: 1 addition & 0 deletions ui/src/main/java/lee/study/down/model/ConfigBaseInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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; //二级代理开关
Expand Down
1 change: 0 additions & 1 deletion ui/src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion ui/src/main/resources/application-prd.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion ui/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
app.version=2.2
app.version=2.21
spring.profiles.active=prd
view.server.port = 8999
tomcat.server.port = 9000
Expand Down
15 changes: 10 additions & 5 deletions ui/src/main/resources/res/pd.pac
Original file line number Diff line number Diff line change
@@ -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';

}
2 changes: 1 addition & 1 deletion update/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>lee.study</groupId>
<artifactId>proxyee-down-update</artifactId>
<packaging>jar</packaging>
<version>2.2</version>
<version>2.21</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down

0 comments on commit 6c914a1

Please sign in to comment.