Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c.Request.RequestURI()在http和https下放回的值不一致 #1229

Open
Jeremyly opened this issue Nov 14, 2024 · 1 comment
Open

c.Request.RequestURI()在http和https下放回的值不一致 #1229

Jeremyly opened this issue Nov 14, 2024 · 1 comment
Labels
invalid issue invalid issue (not related to Hertz or described in document or not enough information provided) stale

Comments

@Jeremyly
Copy link

复现代码如下:

package main

import (
	"context"
	"crypto/tls"
	"fmt"
	"os"
	"time"

	"github.com/cloudwego/hertz/pkg/app"
	"github.com/cloudwego/hertz/pkg/app/server"
	"github.com/cloudwego/hertz/pkg/protocol/consts"
	"github.com/hertz-contrib/http2/config"
	"github.com/hertz-contrib/http2/factory"
	"golang.org/x/net/http2"
)

func main() {
	// set TLS server
	// default is standard.NewTransporter
	h1 := CreateHttpsServer()

	h1.GET("/ping", func(ctx context.Context, c *app.RequestContext) {
		fmt.Println("TLS:" + string(c.Request.RequestURI()))
		c.String(consts.StatusOK, "TLS test\n")
	})

	go h1.Spin()

	h2 := CreateHttpServer()

	h2.GET("/ping", func(ctx context.Context, c *app.RequestContext) {
		fmt.Println("HTTP:" + string(c.Request.RequestURI()))
		c.String(consts.StatusOK, "http test\n")
	})

	h2.Spin()

}

// 创建https服务
func CreateHttpsServer() *server.Hertz {
	// 读取文件内容
	certPEM, err := os.ReadFile("./certificate.crt")
	if err != nil {
		panic(err)
	}

	keyPEM, err := os.ReadFile("./private.key")
	if err != nil {
		panic(err)
	}

	cert, err := tls.X509KeyPair(certPEM, keyPEM)
	if err != nil {
		fmt.Println(err.Error())
	}
	cfg := &tls.Config{
		// add certificate
		Certificates: []tls.Certificate{cert},
		MaxVersion:   tls.VersionTLS13,
		// cipher suites supported
		CipherSuites: []uint16{
			tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
			tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
			tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
		},
		// set application protocol http2
		NextProtos: []string{http2.NextProtoTLS},
	}
	h := server.New(server.WithHostPorts(":https"), server.WithALPN(true), server.WithTLS(cfg))

	// register http2 server factory
	h.AddProtocol("h2", factory.NewServerFactory(
		config.WithReadTimeout(time.Minute),
		config.WithDisableKeepAlive(false)))
	cfg.NextProtos = append(cfg.NextProtos, "h2")

	return h

}

// 创建http服务
func CreateHttpServer() *server.Hertz {
	return server.Default(server.WithHostPorts(":http"))
}

c.Request.RequestURI()方法,在普通的http监听下,返回的值是/ping。而启用了TLS后,返回的值是https://127.0.0.1/ping。返回形式不一致。且注释并没有说明两种场景下有区别。我认为是个bug。

@github-actions github-actions bot added the invalid issue invalid issue (not related to Hertz or described in document or not enough information provided) label Nov 14, 2024
Copy link

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 1 days if no further activity occurs.

@github-actions github-actions bot added the stale label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid issue invalid issue (not related to Hertz or described in document or not enough information provided) stale
Development

No branches or pull requests

1 participant