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

Error in grpc-go as gin middleware #3308

Open
CoiaPrant233 opened this issue Sep 2, 2022 · 1 comment
Open

Error in grpc-go as gin middleware #3308

CoiaPrant233 opened this issue Sep 2, 2022 · 1 comment

Comments

@CoiaPrant233
Copy link

Description

Status code 404 is always returned when grpc-go is used as gin middleware, and it is normal when external grpc is used

How to reproduce

package main

import (
	"github.com/gin-gonic/gin"
        "google.golang.org/grpc"
        "strings"
)

func main() {
        rpc := grpc.NewServer()
        /*
        Register your grpc service
        */

	g := gin.Default()
        g.UseH2C = true
	g.Use(func(c *gin.Context) {
              if c.Request.ProtoMajor == 2 && strings.HasPrefix(c.ContentType(), "application/grpc"){
              rpc.ServeHTTP(c.Writer, c.Request)
              c.Abort()
              return
              }
	})
	g.Run(":9000")
}

Expectations

Use the grpc client to dial to the server and execute RPC Status OK

Actual result

rpc error: code = Unimplemented desc = unexpected HTTP status code received from server: 404 Not Found

Environment

  • go version: v1.18.2
  • gin version: v1.8.1
  • operating system: linux
@CoiaPrant233
Copy link
Author

Preliminary judgment of the problem in the gin. ResponseWriter re-packaged the http.ResponseWriter.
If we could make a middleware type for grpc alone, or add a new method to get the original http. ResponseWriter, the problem would be solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant