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

fix adapter support http2 #1457

Merged
merged 1 commit into from Dec 25, 2022
Merged

fix adapter support http2 #1457

merged 1 commit into from Dec 25, 2022

Conversation

pedia
Copy link
Contributor

@pedia pedia commented Dec 22, 2022

Since the adapter hardcode HTTP/1.1:

	r.Proto = "HTTP/1.1"
	r.ProtoMajor = 1

Maybe this is better?

	r.Proto = b2s(ctx.Request.Header.Protocol())
	if r.Proto == "HTTP/2" {
		r.ProtoMajor = 2
	} else {
		r.ProtoMajor = 1
	}

With this change, compose fasthttp and grpc together is possible.

Usage:

// start server
ws := &fasthttp.Server{...}
http2.ConfigureServer(ws)
ws.ServeTLS(...)

// transform to grpc request
if bytes.Equal(ctx.Request.Header.ContentType(), grpcContentType) {
    fh := fasthttpadaptor.NewFastHTTPHandler(a.Rpc)
    fh(ctx)
    return
}

@li-jin-gou
Copy link
Contributor

I don't think adding this logic to the adapter will adapt to H2, because the protocols for both H2 and H1 are different, and currently fasthttp only does H1 in terms of protocol handling.

@pedia
Copy link
Contributor Author

pedia commented Dec 23, 2022

Agree, This is a small step.

@erikdubbelboer
Copy link
Collaborator

How would this work? In your example you use http2.ConfigureServer(ws) but http2.ConfigureServer expects a http.Server as argument, not a fasthttp.Server.

A fasthttp server isn't be able to receive HTTP/2 requests, so how would that fasthttp.RequestCtx with a Proto of HTTP/2 ever be created?

@pedia
Copy link
Contributor Author

pedia commented Dec 24, 2022

in http2.ConfigureServer(ws), http2 come from https://github.com/dgrr/http2

I think http2.ConfigureServer patched a little.

Testing with curl --http2, it passed.

@erikdubbelboer erikdubbelboer merged commit 9b4a7e5 into valyala:master Dec 25, 2022
@erikdubbelboer
Copy link
Collaborator

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

3 participants