-
Notifications
You must be signed in to change notification settings - Fork 8k
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
support h2c with prior knowledge #1398
Conversation
7cc9267
to
feac8a6
Compare
Codecov Report
@@ Coverage Diff @@
## master #1398 +/- ##
=========================================
- Coverage 98.21% 97.6% -0.61%
=========================================
Files 35 36 +1
Lines 1846 1878 +32
=========================================
+ Hits 1813 1833 +20
- Misses 26 32 +6
- Partials 7 13 +6
Continue to review full report at Codecov.
|
Do you have any plan to keep going this feature? In addition, there is now "golang.org/x/net/http2/h2c" package. I think it is quite simple to complete this with the package. |
Any update on this or maybe it's already implemented? |
hi @thinkerou , it seems some people still need this feature. And I have reimplemented it based on the golang.org/x/net/http2/h2c package. A new |
@appleboy @thinkerou You have any concerns? I also resonate with @epii1 on the usefulness of this feature. |
+1 |
+1, i need this feature also |
1 similar comment
+1, i need this feature also |
+1 |
+1 , any update? |
need @thinkerou approval. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Is gin support h2c ? I don't got this work |
The support for this got released in version 1.8.0. What is the version of gin you are using @ZoeShaw101 ? Release notes - https://github.com/gin-gonic/gin/releases/tag/v1.8.0 |
I'm using gin v1.8.1
|
doesn't supports yet.
|
Oh needed to add these flags router := gin.Default()
router.UseH2C = true |
gin-gonic/gin#1398 Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Another example using r := gin.Default()
r.POST(path+":name", giteaHandler(handler))
r.POST(grpcPath+":name", giteaHandler(gHandler))
r.POST(grpcAlphaPath+":name", giteaHandler(gAlphaHandler))
r.POST(grpcHealthPath+":name", giteaHandler(gHealthHandler))
srv := &http.Server{
Addr: ":8080",
Handler: h2c.NewHandler(
r,
&http2.Server{},
),
ReadHeaderTimeout: time.Second,
ReadTimeout: 5 * time.Minute,
WriteTimeout: 5 * time.Minute,
MaxHeaderBytes: 8 * 1024, // 8KiB
}
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatalf("HTTP listen and serve: %v", err)
} |
Can Gin support custom handler in H2C? func (engine *Engine) Handler(customHandler ...http.Handler) http.Handler gin.UseH2C = true
httpServer := &http.Server{Handler: gin.Handler(customHandler)} |
@ecmap What is the use case you have in mind? |
grpc & rest on the same port |
Support both http/1.x and h2c over the same plain tcp port.
It is common to make h2c communication on the server side environment. However, the standard net/http library does not support this feature in box (more detail). It would be a great convenient for gin to support it.
This patch is extracted from William Chang's work.