Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
energye
energy
提交
95ecc606
energy
项目概览
energye
/
energy
通知
13
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
energy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
95ecc606
编写于
8月 26, 2023
作者:
yanghye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改内置资源XHR代理
上级
a4a217b4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
63 addition
and
22 deletion
+63
-22
cef/browser-config.go
cef/browser-config.go
+1
-1
cef/local-load-resource.go
cef/local-load-resource.go
+17
-14
cef/local-load-xhr-proxy.go
cef/local-load-xhr-proxy.go
+44
-6
example/dev-test/resourcehandler/resourcehandler.go
example/dev-test/resourcehandler/resourcehandler.go
+1
-1
未找到文件。
cef/browser-config.go
浏览文件 @
95ecc606
...
...
@@ -27,7 +27,7 @@ type browserConfig struct {
// LocalResource
// 本地资源加载配置
func
(
m
*
browserConfig
)
LocalResource
(
config
LocalLoadConfig
)
{
func
(
m
*
browserConfig
)
LocalResource
(
config
*
LocalLoadConfig
)
{
localLoadResourceInit
(
config
)
}
...
...
cef/local-load-resource.go
浏览文件 @
95ecc606
...
...
@@ -38,6 +38,7 @@ type LocalLoadResource struct {
// LocalLoadConfig
// 本地&内置资源加载配置
// 然后使用 Build() 函数构建对象
type
LocalLoadConfig
struct
{
Enable
bool
// 设置是否启用本地资源缓存到内存, 默认false: 未启用
EnableCache
bool
// 启用缓存,将加载过的资源存储到内存中
...
...
@@ -64,14 +65,22 @@ type source struct {
}
// 初始化本地加载配置对象
func
localLoadResourceInit
(
config
LocalLoadConfig
)
{
if
localLoadRes
!=
nil
||
config
.
FS
==
nil
{
func
localLoadResourceInit
(
config
*
LocalLoadConfig
)
{
if
config
==
nil
{
return
}
localLoadRes
=
&
LocalLoadResource
{
mimeType
:
make
(
map
[
string
]
string
),
sourceCache
:
make
(
map
[
string
]
*
source
),
}
localLoadRes
.
LocalLoadConfig
=
*
config
}
func
(
m
LocalLoadConfig
)
Build
()
*
LocalLoadConfig
{
if
localLoadRes
!=
nil
{
return
nil
}
var
config
=
&
m
// domain 必须设置
if
config
.
Domain
==
""
{
config
.
Domain
=
localDomain
...
...
@@ -80,11 +89,13 @@ func localLoadResourceInit(config LocalLoadConfig) {
if
config
.
Scheme
!=
LocalCSFile
&&
config
.
Scheme
!=
LocalCSFS
{
config
.
Scheme
=
LocalCSFS
}
// 默认使用 /index.html
if
config
.
Home
==
""
{
config
.
Home
=
"/index.html"
}
else
if
config
.
Home
[
0
]
!=
'/'
{
config
.
Home
=
"/"
+
config
.
Home
}
// 默认的资源目录配置
if
config
.
FileRoot
==
""
{
if
config
.
Scheme
==
LocalCSFS
{
config
.
FileRoot
=
"resources"
...
...
@@ -93,19 +104,11 @@ func localLoadResourceInit(config LocalLoadConfig) {
config
.
FileRoot
=
wd
}
}
//if config.Proxy != nil {
// if proxy, ok := config.Proxy.(*XHRProxy); ok {
// if proxy.Scheme == LpsTcp {
// proxy.tcpListen()
// }
// }
//}
localLoadRes
.
LocalLoadConfig
=
config
}
// 代理配置
if
config
.
Proxy
==
nil
{
func
(
m
LocalLoadConfig
)
SetEnable
(
v
bool
)
LocalLoadConfig
{
m
.
Enable
=
v
return
m
}
return
config
}
func
(
m
*
LocalLoadResource
)
enable
()
bool
{
...
...
cef/local-load-xhr-proxy.go
浏览文件 @
95ecc606
...
...
@@ -13,6 +13,7 @@ package cef
import
(
"bytes"
"crypto/tls"
"embed"
"errors"
.
"github.com/energye/energy/v2/consts"
"github.com/energye/energy/v2/logger"
...
...
@@ -35,12 +36,26 @@ type IXHRProxy interface {
// XHRProxy
// 数据请求代理
type
XHRProxy
struct
{
Scheme
LocalProxyScheme
// http/https/tcp default: http
IP
string
// default: localhost
Port
int
// default: 80
SSLCert
string
// /to/path/cert.crt, https时, 该参数为空跳过检查
SSLKey
string
// /to/path/key.key, https时, 该参数为空跳过检查
SSLCARoot
string
// /to/path/ca.crt, https时, 该参数为空跳过检查
Scheme
LocalProxyScheme
// http/https/tcp default: http
IP
string
// default: localhost
Port
int
// default: 80
SSL
XHRProxySSL
client
*
httpClient
}
// XHRProxySSL
// https证书配置,如果其中某一配置为空,则跳过ssl检查, 如果证书配置错误则请求失败
type
XHRProxySSL
struct
{
FS
*
embed
.
FS
// 证书到内置执行文件时需要设置
RootDir
string
// 根目录, FS不为空时是内置资源目录名,否则是本地硬盘目录
SSLCert
string
// RootDir/to/path/cert.crt
SSLKey
string
// RootDir/to/path/key.key
SSLCARoot
string
// RootDir/to/path/ca.crt
}
type
httpClient
struct
{
tr
*
http
.
Transport
client
http
.
Client
}
// XHRProxyResponse
...
...
@@ -52,6 +67,10 @@ type XHRProxyResponse struct {
Header
map
[
string
][]
string
// 响应头
}
func
(
m
*
XHRProxySSL
)
skipVerify
()
bool
{
return
m
.
RootDir
==
""
||
m
.
SSLCert
==
""
||
m
.
SSLKey
==
""
||
m
.
SSLCARoot
==
""
}
func
(
m
*
XHRProxy
)
Send
(
request
*
ICefRequest
)
(
*
XHRProxyResponse
,
error
)
{
if
m
.
Scheme
==
LpsHttp
{
return
m
.
sendHttp
(
request
)
...
...
@@ -125,6 +144,7 @@ func (m *XHRProxy) sendHttp(request *ICefRequest) (*XHRProxyResponse, error) {
cli
:=
&
http
.
Client
{
Jar
:
jar
,
}
cli
.
CloseIdleConnections
()
httpResponse
,
err
:=
cli
.
Do
(
httpRequest
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -164,6 +184,24 @@ func (m *XHRProxy) sendHttps(request *ICefRequest) (*XHRProxyResponse, error) {
//}
//certPool := x509.NewCertPool()
//certPool.AppendCertsFromPEM(crt)
//if m.client == nil {
// m.client = &httpClient{}
// var config *tls.Config
// if m.SSL.skipVerify() {
//
// } else {
//
// }
//
// m.client.tr = &http.Transport{
// TLSClientConfig: &tls.Config{
// InsecureSkipVerify: true,
// //Certificates: []tls.Certificate{cert},
// //RootCAs: certPool,
// },
// }
//}
tr
:=
&
http
.
Transport
{
TLSClientConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
true
,
...
...
example/dev-test/resourcehandler/resourcehandler.go
浏览文件 @
95ecc606
...
...
@@ -33,7 +33,7 @@ func main() {
Scheme
:
consts
.
LpsHttps
,
IP
:
"energy.yanghy.cn"
,
},
})
}
.
Build
()
)
if
common
.
IsLinux
()
&&
app
.
IsUIGtk3
()
{
cef
.
BrowserWindow
.
Config
.
IconFS
=
"resources/icon.png"
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录