Closed
Description
I'm trying to make an endpoint which streams bytes (i.e. file) and sets 'Content-Disposition' header for suggested filename. Because the Swagger complains that ByteString
is impossible, I have the newtype around it
type API = "file" :> StreamGet NoFraming OctetStream (Headers '[ContDispHdr] StreamData)
newtype ByteStream = ByteStream {unBS :: BS.ByteString}
deriving (Generic, Show, Semigroup)
type ContDispHdr = Header "Content-Disposition" String
type StreamData = SourceIO ByteStream
server :: Handler (Headers '[ContDispHdr] StreamData)
curl
and httpLbs
seem to work correctly, however, client function complains about missing FromSourceIO
getFile :: ClientM (Headers '[ContDispHdr] StreamData)
getFile = client (Proxy :: Proxy API)
instance FromSourceIO ByteStream (Headers '[ContDispHdr] StreamData) where
fromSourceIO _src = ???
I (obviously) failed in creating one, so could someone help in how to do it or
is there a better way in creating the endpoint that
- returns a stream
- sets different 'Content-Disposition' header
- sets different 'Content-Type' header (depending on the stream type)?
I have a file for testing
Metadata
Metadata
Assignees
Labels
No labels