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

Mark final chunk as final #1

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Network/HTTP/Semantics/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Network.HTTP.Semantics.Client (
responseHeaders,
responseBodySize,
getResponseBodyChunk,
getResponseBodyChunk',
getResponseTrailers,

-- * Aux
Expand Down Expand Up @@ -133,7 +134,11 @@ responseBodySize (Response rsp) = inpObjBodySize rsp
-- | Reading a chunk of the response body.
-- An empty 'ByteString' returned when finished.
getResponseBodyChunk :: Response -> IO ByteString
getResponseBodyChunk (Response rsp) = inpObjBody rsp
getResponseBodyChunk = fmap fst . getResponseBodyChunk'

-- | Generalization of 'getResponseBodyChunk' which also returns if the 'ByteString' is the final one
getResponseBodyChunk' :: Response -> IO (ByteString, Bool)
getResponseBodyChunk' (Response rsp) = inpObjBody rsp

-- | Reading response trailers.
-- This function must be called after 'getResponseBodyChunk'
Expand Down
7 changes: 6 additions & 1 deletion Network/HTTP/Semantics/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Network.HTTP.Semantics.Server (
requestHeaders,
requestBodySize,
getRequestBodyChunk,
getRequestBodyChunk',
getRequestTrailers,

-- * Aux
Expand Down Expand Up @@ -125,7 +126,11 @@ requestBodySize (Request req) = inpObjBodySize req
-- | Reading a chunk of the request body.
-- An empty 'ByteString' returned when finished.
getRequestBodyChunk :: Request -> IO ByteString
getRequestBodyChunk (Request req) = inpObjBody req
getRequestBodyChunk = fmap fst . getRequestBodyChunk'

-- | Generalization of 'getRequestBodyChunk' which also returns if the 'ByteString' is the final one
getRequestBodyChunk' :: Request -> IO (ByteString, Bool)
getRequestBodyChunk' (Request req) = inpObjBody req

-- | Reading request trailers.
-- This function must be called after 'getRequestBodyChunk'
Expand Down
2 changes: 1 addition & 1 deletion Network/HTTP/Semantics/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Path = ByteString

----------------------------------------------------------------

type InpBody = IO ByteString
type InpBody = IO (ByteString, Bool)

data OutBody
= OutBodyNone
Expand Down