Skip to content

fromSourceIO for endpoint with Headers #1170

Closed
@vlatkoB

Description

@vlatkoB

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions