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

Introduce responseStreamingIface #9

Merged

Conversation

FinleyMcIlwaine
Copy link
Collaborator

Prior to this commit, when a server finished streaming, it had no way of indicating this (i.e. it has no way of setting the second argument to StreamingBuilder). As a result, http2 would emit a final DATA frame when it finished the processing the builder along with a subsequent empty data frame when processing StreamingFinished. This results in an empty data frame at the end of every response. If the volume of responses is high, this even triggers the emptyFrameRateLimit in http2.

Prior to this commit, when a server finished streaming, it had no way of
indicating this (i.e. it has no way of setting the second argument to
`StreamingBuilder`). As a result, `http2` would emit a final DATA frame when it
finished the processing the builder along with a subsequent *empty* data frame
when processing `StreamingFinished`. This results in an empty data frame at the
end of every response. If the volume of responses is high, this even triggers
the `emptyFrameRateLimit` in `http2`.
@edsko
Copy link
Collaborator

edsko commented Jul 12, 2024

@kazu-yamamoto We renamed OutBodyStreamingUnmask to OutBodyStreamingIface: the point is to have a more general interface, which is important in both the client and the server, which might also support unmasking (but this only does something in the client). We also introduced a new datatype for the "end of stream" indicator; previously, this was Maybe CleanupStream, which was confusing: it suggested that if you don't need any stream cleanup, you can just set that to Nothing, but that is incorrect: it should have been set to Just (return ()). The new EndOfStream datatype makes this a lot clearer.

dec
finished :: Maybe CleanupStream -> NextWithTotal
finished mdec = \total _buf _room -> do
fromMaybe (return ()) mdec
return $ Next total True Nothing
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the future, it might make sense to avoid requesting a flush here if total == 0, to prevent any empty data frames from being sent.

@kazu-yamamoto kazu-yamamoto self-requested a review July 14, 2024 05:00
Copy link
Owner

@kazu-yamamoto kazu-yamamoto left a comment

Choose a reason for hiding this comment

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

LGTM

@kazu-yamamoto kazu-yamamoto merged commit d4315ba into kazu-yamamoto:main Jul 14, 2024
@kazu-yamamoto
Copy link
Owner

Merged. Thanks!

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Jan 30, 2025
## 0.3.0

* Breaking change: fillFileBodyGetNext takes Sentinel instead of
  IO () to close files on time.

## 0.2.1

* Add outBodyCancel to OutBodyIface
  [#11](kazu-yamamoto/http-semantics#11)
* Documentation improvement.
  [#10](kazu-yamamoto/http-semantics#10)
  [#11](kazu-yamamoto/http-semantics#11)

## 0.2.0

* Introduce `responseStreamingIface`
  [#9](kazu-yamamoto/http-semantics#9)

## 0.1.2

* Avoid buffer overflow in fillBufBuilderOne
  [#4](kazu-yamamoto/http-semantics#4)

## 0.1.1

* Avoid buffer overflow in runStreamingBuilder
  [#3](kazu-yamamoto/http-semantics#3)

## 0.1.0

* Make it possible to guarantee that final DATA frame is marked end-of-stream.
  [#2](kazu-yamamoto/http-semantics#2)

## 0.0.1

* Defining getResponseBodyChunk'.
  [#1](kazu-yamamoto/http-semantics#1)
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.

3 participants