Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
energye
energy
提交
a4a217b4
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,发现更多精彩内容 >>
提交
a4a217b4
编写于
8月 26, 2023
作者:
yanghye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改 内置资源XHR代理请求
上级
97cce37d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
10 addition
and
32 deletion
+10
-32
cef/local-load-resource.go
cef/local-load-resource.go
+1
-3
cef/local-load-xhr-proxy.go
cef/local-load-xhr-proxy.go
+5
-27
example/dev-test/resourcehandler/resourcehandler.go
example/dev-test/resourcehandler/resourcehandler.go
+4
-2
未找到文件。
cef/local-load-resource.go
浏览文件 @
a4a217b4
...
...
@@ -12,7 +12,6 @@ package cef
import
(
"embed"
"fmt"
.
"github.com/energye/energy/v2/consts"
"github.com/energye/energy/v2/logger"
"io/ioutil"
...
...
@@ -44,7 +43,7 @@ type LocalLoadConfig struct {
EnableCache
bool
// 启用缓存,将加载过的资源存储到内存中
Domain
string
// 必须设置的域
Scheme
LocalCustomerScheme
// 自定义协议, file: 本地磁盘目录加载, fs: 内置到执行程序加载
FileRoot
string
// 资源根目录, scheme是file时为本地目录(默认当前程序执行目录) scheme是fs时为
资源文件夹名
, 默认:[resources or /current/path]
FileRoot
string
// 资源根目录, scheme是file时为本地目录(默认当前程序执行目录) scheme是fs时为
resources
, 默认:[resources or /current/path]
FS
*
embed
.
FS
// 内置加载资源对象, scheme是fs时必须填入
Proxy
IXHRProxy
// 数据请求代理, 在浏览器发送xhr请求时可通过该配置转发, 你可自定义实现该 IXHRProxy 接口
Home
string
// 默认首页: /index.html, /home.html, /other.html, default: /index.html
...
...
@@ -268,7 +267,6 @@ func (m *source) response(response *ICefResponse) (responseLength int64, redirec
for
key
,
value
:=
range
m
.
header
{
for
_
,
vs
:=
range
value
{
header
.
Append
(
key
,
vs
)
fmt
.
Println
(
"source response header:"
,
key
,
"="
,
vs
)
}
}
response
.
SetHeaderMap
(
header
)
...
...
cef/local-load-xhr-proxy.go
浏览文件 @
a4a217b4
...
...
@@ -14,7 +14,6 @@ import (
"bytes"
"crypto/tls"
"errors"
"fmt"
.
"github.com/energye/energy/v2/consts"
"github.com/energye/energy/v2/logger"
"io/ioutil"
...
...
@@ -27,6 +26,8 @@ import (
// cookies jar
var
jar
,
_
=
cookiejar
.
New
(
nil
)
// IXHRProxy
// 本地资源加载 XHR 请求代理接口
type
IXHRProxy
interface
{
Send
(
request
*
ICefRequest
)
(
*
XHRProxyResponse
,
error
)
// 发送请求,在浏览器进程同步执行
}
...
...
@@ -84,7 +85,6 @@ func (m *XHRProxy) sendHttp(request *ICefRequest) (*XHRProxyResponse, error) {
elements
:=
postData
.
GetElements
()
for
i
:=
0
;
i
<
dataCount
;
i
++
{
element
:=
elements
.
Get
(
uint32
(
i
))
fmt
.
Println
(
"element-type:"
,
element
.
GetType
())
switch
element
.
GetType
()
{
case
PDE_TYPE_EMPTY
:
case
PDE_TYPE_BYTES
:
...
...
@@ -113,23 +113,14 @@ func (m *XHRProxy) sendHttp(request *ICefRequest) (*XHRProxyResponse, error) {
size
:=
header
.
GetSize
()
for
i
:=
0
;
i
<
int
(
size
);
i
++
{
key
:=
header
.
GetKey
(
uint32
(
i
))
//value := header.GetValue(uint32(i))
//httpRequest.Header.Add(key, value)
c
:=
header
.
FindCount
(
key
)
for
j
:=
0
;
j
<
int
(
c
);
j
++
{
value
:=
header
.
GetEnumerate
(
key
,
uint32
(
j
))
httpRequest
.
Header
.
Add
(
key
,
value
)
fmt
.
Println
(
"XHRProxy Request header:"
,
key
,
"="
,
value
,
"url:"
,
targetUrl
.
String
())
}
}
header
.
Free
()
}
//Host: energy.yanghy.cn
//Origin: https://energy.yanghy.cn
//Referer: https://energy.yanghy.cn/
httpRequest
.
Header
.
Add
(
"Host"
,
"energy.yanghy.cn"
)
httpRequest
.
Header
.
Add
(
"Origin"
,
"http://energy.yanghy.cn"
)
httpRequest
.
Header
.
Add
(
"Referer"
,
"http://energy.yanghy.cn/"
)
// 创建 client
cli
:=
&
http
.
Client
{
Jar
:
jar
,
...
...
@@ -148,7 +139,6 @@ func (m *XHRProxy) sendHttp(request *ICefRequest) (*XHRProxyResponse, error) {
}
else
{
responseHeader
[
key
]
=
[]
string
{
vs
}
}
fmt
.
Println
(
"XHRProxy response header:"
,
key
,
"="
,
vs
,
"url:"
,
targetUrl
.
String
())
}
}
// 读取响应数据
...
...
@@ -160,7 +150,6 @@ func (m *XHRProxy) sendHttp(request *ICefRequest) (*XHRProxyResponse, error) {
StatusCode
:
int32
(
httpResponse
.
StatusCode
),
Header
:
responseHeader
,
}
fmt
.
Println
(
"XHRProxy response result:"
,
result
.
DataSize
,
result
.
StatusCode
,
"url:"
,
targetUrl
.
String
())
return
result
,
nil
}
...
...
@@ -203,14 +192,11 @@ func (m *XHRProxy) sendHttps(request *ICefRequest) (*XHRProxyResponse, error) {
// 读取请求数据
requestData
:=
new
(
bytes
.
Buffer
)
postData
:=
request
.
GetPostData
()
fmt
.
Println
(
"element- postData.IsValid():"
,
postData
.
IsValid
())
if
postData
.
IsValid
()
{
dataCount
:=
int
(
postData
.
GetElementCount
())
elements
:=
postData
.
GetElements
()
fmt
.
Println
(
"element-dataCount:"
,
dataCount
)
for
i
:=
0
;
i
<
dataCount
;
i
++
{
element
:=
elements
.
Get
(
uint32
(
i
))
fmt
.
Println
(
"element-type:"
,
element
.
GetType
())
switch
element
.
GetType
()
{
case
PDE_TYPE_EMPTY
:
case
PDE_TYPE_BYTES
:
...
...
@@ -239,23 +225,17 @@ func (m *XHRProxy) sendHttps(request *ICefRequest) (*XHRProxyResponse, error) {
size
:=
header
.
GetSize
()
for
i
:=
0
;
i
<
int
(
size
);
i
++
{
key
:=
header
.
GetKey
(
uint32
(
i
))
//value := header.GetValue(uint32(i))
//httpRequest.Header.Add(key, value)
c
:=
header
.
FindCount
(
key
)
for
j
:=
0
;
j
<
int
(
c
);
j
++
{
value
:=
header
.
GetEnumerate
(
key
,
uint32
(
j
))
httpRequest
.
Header
.
Add
(
key
,
value
)
fmt
.
Println
(
"XHRProxy Request header:"
,
key
,
"="
,
value
,
"url:"
,
targetUrl
.
String
())
}
}
header
.
Free
()
}
//Host: energy.yanghy.cn
//Origin: https://energy.yanghy.cn
//Referer: https://energy.yanghy.cn/
httpRequest
.
Header
.
Add
(
"Host"
,
"energy.yanghy.cn"
)
httpRequest
.
Header
.
Add
(
"Origin"
,
"https://energy.yanghy.cn"
)
httpRequest
.
Header
.
Add
(
"Referer"
,
"https://energy.yanghy.cn/"
)
//httpRequest.Header.Add("Host", "energy.yanghy.cn")
//httpRequest.Header.Add("Origin", "https://energy.yanghy.cn")
//httpRequest.Header.Add("Referer", "https://energy.yanghy.cn/")
httpResponse
,
err
:=
cli
.
Do
(
httpRequest
)
if
err
!=
nil
{
...
...
@@ -271,7 +251,6 @@ func (m *XHRProxy) sendHttps(request *ICefRequest) (*XHRProxyResponse, error) {
}
else
{
responseHeader
[
key
]
=
[]
string
{
vs
}
}
fmt
.
Println
(
"XHRProxy response header:"
,
key
,
"="
,
vs
,
"url:"
,
targetUrl
.
String
())
}
}
// 读取响应数据
...
...
@@ -283,7 +262,6 @@ func (m *XHRProxy) sendHttps(request *ICefRequest) (*XHRProxyResponse, error) {
StatusCode
:
int32
(
httpResponse
.
StatusCode
),
Header
:
responseHeader
,
}
fmt
.
Println
(
"XHRProxy response result:"
,
result
.
DataSize
,
result
.
StatusCode
,
"url:"
,
targetUrl
.
String
())
return
result
,
nil
}
...
...
example/dev-test/resourcehandler/resourcehandler.go
浏览文件 @
a4a217b4
...
...
@@ -20,13 +20,15 @@ func main() {
cef
.
GlobalInit
(
nil
,
&
resources
)
//创建应用
var
app
=
cef
.
NewApplication
()
app
.
SetDisableBackForwardCache
(
true
)
//app.SetDisableWebSecurity(true)
//指定一个URL地址,或本地html文件目录
cef
.
BrowserWindow
.
Config
.
Url
=
"fs://energy/index.html"
cef
.
BrowserWindow
.
Config
.
Title
=
"Energy - Local load"
cef
.
BrowserWindow
.
Config
.
LocalResource
(
cef
.
LocalLoadConfig
{
Enable
:
true
,
FS
:
&
resources
,
Enable
:
true
,
FileRoot
:
"resources/dist"
,
FS
:
&
resources
,
Proxy
:
&
cef
.
XHRProxy
{
Scheme
:
consts
.
LpsHttps
,
IP
:
"energy.yanghy.cn"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录