提交 feadef04 编写于 作者: yanghye's avatar yanghye

修改内置资源XHR代理注释说明

上级 3694611b
......@@ -27,6 +27,7 @@ type browserConfig struct {
// LocalResource
// 本地资源加载配置
// 在浏览器进程初始化
func (m *browserConfig) LocalResource(config *LocalLoadConfig) {
localLoadResourceInit(config)
}
......
......@@ -35,11 +35,15 @@ type windowCurrentProperty struct {
// 提供部分窗口属性配置,初始化时生效
// 如需更多属性配置或自定义窗口行为请在`SetBrowserInit`回调函数中使用
type WindowProperty struct {
IsShowModel bool // 是否以模态窗口显示
WindowInitState types.TWindowState // 窗口 初始状态: 最小化、最大化、全屏, 全屏时隐藏标题栏生效
WindowType consts.WINDOW_TYPE // 窗口 类型 WINDOW_TYPE default: WT_MAIN_BROWSER
Title string // 窗口 标题
Url string // 默认打开URL
IsShowModel bool // 是否以模态窗口显示
WindowInitState types.TWindowState // 窗口 初始状态: 最小化、最大化、全屏, 全屏时隐藏标题栏生效
WindowType consts.WINDOW_TYPE // 窗口 类型 WINDOW_TYPE default: WT_MAIN_BROWSER
Title string // 窗口 标题
//Url 默认打开URL, 支持http和LocalLoad(本地资源)加载方式
// http方式: http://www.example.com, LocalLoad方式: fs://energy/index.html, or file://energy/index.html
// http: 需要web服务支持, LocalLoad: 不需要web服务支持, 如果浏览器调用数据接口需要配置代理
// LocalLoad: 通过 Config.LocalResource 配置实现
Url string
Icon string // 窗口图标 加载本地图标 local > /app/resources/icon.ico, VF窗口linux使用png
IconFS string // 窗口图标 加载emfs内置图标 emfs > resources/icon.ico, VF窗口linux使用png
EnableWebkitAppRegion bool //
......
......@@ -77,6 +77,9 @@ func localLoadResourceInit(config *LocalLoadConfig) {
localLoadRes.LocalLoadConfig = *config
}
// Build
// 构建本地资源加载配置
// 初始化默认值和默认代理配置
func (m LocalLoadConfig) Build() *LocalLoadConfig {
if localLoadRes != nil && !process.Args.IsMain() {
return nil
......
......@@ -188,10 +188,11 @@ func (m *XHRProxy) send(scheme string, request *ICefRequest) (*XHRProxyResponse,
if err != nil {
return nil, err
}
// 构造目标地址
targetUrl := new(bytes.Buffer)
targetUrl.WriteString(scheme)
targetUrl.WriteString(m.IP)
if m.Port > 0 {
if m.Port > 0 { // ip:port
targetUrl.WriteString(":")
targetUrl.WriteString(strconv.Itoa(m.Port))
}
......@@ -199,10 +200,10 @@ func (m *XHRProxy) send(scheme string, request *ICefRequest) (*XHRProxyResponse,
targetUrl.WriteString(reqUrl.RawQuery)
// 读取请求数据
requestData := new(bytes.Buffer)
postData := request.GetPostData()
if postData.IsValid() {
dataCount := int(postData.GetElementCount())
elements := postData.GetElements()
data := request.GetPostData()
if data.IsValid() {
dataCount := int(data.GetElementCount())
elements := data.GetElements()
for i := 0; i < dataCount; i++ {
element := elements.Get(uint32(i))
switch element.GetType() {
......@@ -220,10 +221,11 @@ func (m *XHRProxy) send(scheme string, request *ICefRequest) (*XHRProxyResponse,
}
element.Free()
}
postData.Free()
data.Free()
}
logger.Debug("XHRProxy TargetURL:", targetUrl.String(), "method:", request.Method(), "dataLength:", len(requestData.Bytes()))
httpRequest, err := http.NewRequest(request.Method(), targetUrl.String(), requestData)
tarUrl := targetUrl.String()
logger.Debug("XHRProxy URL:", tarUrl, "method:", request.Method(), "length:", requestData.Len())
httpRequest, err := http.NewRequest(request.Method(), tarUrl, requestData)
if err != nil {
return nil, err
}
......@@ -241,11 +243,9 @@ func (m *XHRProxy) send(scheme string, request *ICefRequest) (*XHRProxyResponse,
}
header.Free()
}
//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", "www.example.com")
//httpRequest.Header.Add("Origin", "https://www.example.com")
//httpRequest.Header.Add("Referer", "https://www.example.com/")
httpResponse, err := m.HttpClient.Client.Do(httpRequest)
if err != nil {
return nil, err
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册