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

Add trailer support #1165

Merged
merged 9 commits into from Dec 5, 2021
Merged

Add trailer support #1165

merged 9 commits into from Dec 5, 2021

Conversation

ichxxx
Copy link
Contributor

@ichxxx ichxxx commented Nov 24, 2021

This is in reference to #1078 , #210 .
This will allow FastHTTP to support trailer for chunked transfers.

Write trailer

For example:

resp := &Response{}
resp.Header.Set("Trailer", "Foo")
// write body
resp.Header.Set("Foo", "bar")

req := &Request{}
req.Header.SetTrailer("Foo")
// write body
req.Header.Set("Foo", "bar")

Header Foo will send after the chunked body.

Read trailer

For example:

func(ctx *RequestCtx) {
    ioutil.ReadAll(ctx.RequestBodyStream())
    ctx.Request.Header.VisitAllTrailer(func(key []byte) {
        trailer := ctx.Request.Header.PeekBytes(key)
        // do something
    })
}

Trailer can be found by inspecting Header after reading all chunked body.

Copy link
Collaborator

@erikdubbelboer erikdubbelboer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint is failing: https://github.com/valyala/fasthttp/runs/4310069291?check_suite_focus=true

Can you add some clear documentation that trailers are only supported with chunked bodies?

header.go Outdated Show resolved Hide resolved
header.go Outdated Show resolved Hide resolved
header.go Outdated Show resolved Hide resolved
header.go Outdated Show resolved Hide resolved
header.go Outdated Show resolved Hide resolved
header.go Show resolved Hide resolved
header.go Show resolved Hide resolved
header.go Outdated Show resolved Hide resolved
header.go Show resolved Hide resolved
header.go Show resolved Hide resolved
@ichxxx
Copy link
Contributor Author

ichxxx commented Nov 29, 2021

Lint is failing: https://github.com/valyala/fasthttp/runs/4310069291?check_suite_focus=true

Can you add some clear documentation that trailers are only supported with chunked bodies?

Sure.

header.go Outdated Show resolved Hide resolved
@ichxxx
Copy link
Contributor Author

ichxxx commented Dec 3, 2021

Seems the tests are a bit flaky.

@erikdubbelboer
Copy link
Collaborator

Seems the tests are a bit flaky.

Yeah they are. You can ignore that.

header.go Outdated Show resolved Hide resolved
header.go Outdated Show resolved Hide resolved
@erikdubbelboer
Copy link
Collaborator

Sorry for asking for so many changes. I'm super happy that you wrote this code. But it's also quite a lot and important to get right I think.

@ichxxx
Copy link
Contributor Author

ichxxx commented Dec 3, 2021

This is not a problem at all. It's always better to be strict with code. I have also learned a lot from this pr.

header.go Outdated Show resolved Hide resolved
header.go Outdated Show resolved Hide resolved
header.go Outdated Show resolved Hide resolved
server_test.go Outdated Show resolved Hide resolved
server_test.go Outdated Show resolved Hide resolved
streaming_test.go Outdated Show resolved Hide resolved
streaming_test.go Outdated Show resolved Hide resolved
streaming_test.go Outdated Show resolved Hide resolved
@erikdubbelboer erikdubbelboer merged commit da7ff7a into valyala:master Dec 5, 2021
@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

2 participants