I am trying to pass a part of ByteString back to the client (browser). The client will not know the content type of the requested document, so I am trying to send the appropriate content type response back to the client. The document may be an image or a document in pdf format or words, etc.
For example, the client will request /document?id=55 , and the server will respond with the appropriate content type and associated ByteString .
I followed suit here : and I created something for the image.
data IMAGE instance Accept IMAGE where contentType _ = "image" M.// "jpeg" instance MimeRender IMAGE LBS.ByteString where mimeRender _ = id
The problem is that the client will not send a request with a specific Accept: header, so I donβt need to react with the corresponding Mime type, how it is done. Plus, the above will work only for images (provided that browsers display png even I send jpeg back), but not for pdf , docx , etc.
I was thinking of a parameterized type of type MyDynamicContent String , and I will pass the content type at runtime, but I'm not sure how I will declare my API, that is, what I will use instead of '[JSON] . Not sure if such a thing is even possible, because examples are just a simple data type.
So my question is: if I want to send some ByteString as an answer and dynamically set the Content-Type header, what would be the best way to do this using servant
Update: I opened issue
source share