From 8af107c5843fe9c30ee33446637cc33f6557a34e Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Fri, 11 Apr 2025 07:24:50 +0800 Subject: [PATCH] update for touka-httpc 0.4.0 --- CHANGELOG.md | 7 ++++++- DEV-VERSION | 2 +- main.go | 5 +++++ proxy/httpc.go | 43 ++++++++++++++++++++++++++++++------------- 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 979cb00..bc0931e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # 更新日志 -3.0.1 -2025-04-08 +25w28t-1 - 2025-04-11 +--- +- TEST: 测试验证版本 +- CHANGE: 更新httpc 0.4.0 + +3.0.1 - 2025-04-08 --- - CHANGE: 加入`memLimit`指示gc - CHANGE: 加入`hlog`输出路径配置 diff --git a/DEV-VERSION b/DEV-VERSION index 03ab3b3..42eb3c3 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w27a \ No newline at end of file +25w28t-1 \ No newline at end of file diff --git a/main.go b/main.go index cd21df2..d766a9f 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,8 @@ import ( "github.com/cloudwego/hertz/pkg/common/adaptor" "github.com/cloudwego/hertz/pkg/common/hlog" + //"github.com/cloudwego/hertz/pkg/network/standard" + "github.com/hertz-contrib/http2/factory" ) @@ -146,6 +148,7 @@ func setupHertZLogger(cfg *config.Config) { } else { hlog.SetOutput(hertZfile) } + hlog.SetLevel(hlog.LevelInfo) } } @@ -377,6 +380,8 @@ func main() { r = server.New( server.WithHostPorts(addr), server.WithH2C(true), + // server.WithALPN(true), + // server.WithTransport(standard.NewTransporter), ) r.AddProtocol("h2", factory.NewServerFactory()) } else { diff --git a/proxy/httpc.go b/proxy/httpc.go index 117f26b..80e4510 100644 --- a/proxy/httpc.go +++ b/proxy/httpc.go @@ -87,23 +87,12 @@ func initHTTPClient(cfg *config.Config) { func initGitHTTPClient(cfg *config.Config) { - var proTolcols = new(http.Protocols) - proTolcols.SetHTTP1(true) - proTolcols.SetHTTP2(true) - proTolcols.SetUnencryptedHTTP2(true) - if cfg.GitClone.ForceH2C { - proTolcols.SetHTTP1(false) - proTolcols.SetHTTP2(false) - proTolcols.SetUnencryptedHTTP2(true) - } if cfg.Httpc.Mode == "auto" { - gittr = &http.Transport{ //MaxIdleConns: 160, IdleConnTimeout: 30 * time.Second, WriteBufferSize: 32 * 1024, // 32KB ReadBufferSize: 32 * 1024, // 32KB - Protocols: proTolcols, } } else if cfg.Httpc.Mode == "advanced" { gittr = &http.Transport{ @@ -112,7 +101,6 @@ func initGitHTTPClient(cfg *config.Config) { MaxIdleConnsPerHost: cfg.Httpc.MaxIdleConnsPerHost, WriteBufferSize: 32 * 1024, // 32KB ReadBufferSize: 32 * 1024, // 32KB - Protocols: proTolcols, } } else { // 错误的模式 @@ -130,14 +118,43 @@ func initGitHTTPClient(cfg *config.Config) { if cfg.Outbound.Enabled { initTransport(cfg, gittr) } - if cfg.Server.Debug { + if cfg.Server.Debug && cfg.GitClone.ForceH2C { gitclient = httpc.New( httpc.WithTransport(gittr), httpc.WithDumpLog(), + httpc.WithProtocols(httpc.ProtocolsConfig{ + Http1: false, + Http2: false, + Http2_Cleartext: true, + }), + ) + } else if !cfg.Server.Debug && cfg.GitClone.ForceH2C { + gitclient = httpc.New( + httpc.WithTransport(gittr), + httpc.WithProtocols(httpc.ProtocolsConfig{ + Http1: false, + Http2: false, + Http2_Cleartext: true, + }), + ) + } else if cfg.Server.Debug && !cfg.GitClone.ForceH2C { + gitclient = httpc.New( + httpc.WithTransport(gittr), + httpc.WithDumpLog(), + httpc.WithProtocols(httpc.ProtocolsConfig{ + Http1: true, + Http2: true, + Http2_Cleartext: true, + }), ) } else { gitclient = httpc.New( httpc.WithTransport(gittr), + httpc.WithProtocols(httpc.ProtocolsConfig{ + Http1: true, + Http2: true, + Http2_Cleartext: true, + }), ) } }