mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-07 04:38:19 +08:00
Compare commits
4 Commits
16c0888678
...
e47fcea040
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e47fcea040 | ||
|
|
0a71eab38f | ||
|
|
5f4f964325 | ||
|
|
47a03c7cf2 |
2
.github/workflows/gin.yml
vendored
2
.github/workflows/gin.yml
vendored
@ -78,6 +78,6 @@ jobs:
|
||||
run: make test
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v5
|
||||
uses: codecov/codecov-action@v6
|
||||
with:
|
||||
flags: ${{ matrix.os }},go-${{ matrix.go }},${{ matrix.test-tags }}
|
||||
|
||||
4
.github/workflows/trivy-scan.yml
vendored
4
.github/workflows/trivy-scan.yml
vendored
@ -27,7 +27,7 @@ jobs:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Run Trivy vulnerability scanner (source code)
|
||||
uses: aquasecurity/trivy-action@0.35.0
|
||||
uses: aquasecurity/trivy-action@v0.36.0
|
||||
with:
|
||||
scan-type: "fs"
|
||||
scan-ref: "."
|
||||
@ -44,7 +44,7 @@ jobs:
|
||||
sarif_file: "trivy-results.sarif"
|
||||
|
||||
- name: Run Trivy scanner (table output for logs)
|
||||
uses: aquasecurity/trivy-action@0.35.0
|
||||
uses: aquasecurity/trivy-action@v0.36.0
|
||||
if: always()
|
||||
with:
|
||||
scan-type: "fs"
|
||||
|
||||
8
gin.go
8
gin.go
@ -169,6 +169,11 @@ type Engine struct {
|
||||
// UseH2C enable h2c support.
|
||||
UseH2C bool
|
||||
|
||||
// H2CConfig optionally specifies the http2.Server configuration used for h2c connections.
|
||||
// If nil, a default &http2.Server{} is used. Set this to configure options such as
|
||||
// MaxConcurrentStreams, IdleTimeout, etc.
|
||||
H2CConfig *http2.Server
|
||||
|
||||
// ContextWithFallback enable fallback Context.Deadline(), Context.Done(), Context.Err() and Context.Value() when Context.Request.Context() is not nil.
|
||||
ContextWithFallback bool
|
||||
|
||||
@ -246,6 +251,9 @@ func (engine *Engine) Handler() http.Handler {
|
||||
}
|
||||
|
||||
h2s := &http2.Server{}
|
||||
if engine.H2CConfig != nil {
|
||||
h2s = engine.H2CConfig
|
||||
}
|
||||
return h2c.NewHandler(engine, h2s)
|
||||
}
|
||||
|
||||
|
||||
49
gin_test.go
49
gin_test.go
@ -120,6 +120,55 @@ func TestH2c(t *testing.T) {
|
||||
assert.Equal(t, "<h1>Hello world</h1>", string(resp))
|
||||
}
|
||||
|
||||
func TestH2CHandlerDefaultConfig(t *testing.T) {
|
||||
r := Default()
|
||||
r.UseH2C = true
|
||||
handler := r.Handler()
|
||||
// When UseH2C is true and H2CConfig is nil, Handler() should return an h2c handler (not the engine itself).
|
||||
assert.NotEqual(t, r, handler)
|
||||
}
|
||||
|
||||
func TestH2CHandlerWithCustomConfig(t *testing.T) {
|
||||
ln, err := net.Listen("tcp", localhostIP+":0")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
r := Default()
|
||||
r.UseH2C = true
|
||||
r.H2CConfig = &http2.Server{
|
||||
IdleTimeout: 60 * time.Second,
|
||||
}
|
||||
r.GET("/", func(c *Context) {
|
||||
c.String(200, "<h1>Hello world</h1>")
|
||||
})
|
||||
go func() {
|
||||
err := http.Serve(ln, r.Handler())
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}()
|
||||
defer ln.Close()
|
||||
|
||||
url := "http://" + ln.Addr().String() + "/"
|
||||
|
||||
httpClient := http.Client{
|
||||
Transport: &http2.Transport{
|
||||
AllowHTTP: true,
|
||||
DialTLS: func(netw, addr string, cfg *tls.Config) (net.Conn, error) {
|
||||
return net.Dial(netw, addr)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
res, err := httpClient.Get(url)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
resp, _ := io.ReadAll(res.Body)
|
||||
assert.Equal(t, "<h1>Hello world</h1>", string(resp))
|
||||
}
|
||||
|
||||
func TestLoadHTMLGlobTestMode(t *testing.T) {
|
||||
ts := setupHTMLFiles(
|
||||
t,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user