11module ConcurrentTask.Http exposing
22 ( request, get, post
33 , Body , emptyBody, stringBody, jsonBody, bytesBody
4- , Expect , expectJson, expectString, expectBytes, expectWhatever, withMetadata
4+ , Expect , expectJson, expectString, expectBytes, expectRawBytes , expectWhatever, withMetadata
55 , Header , header
66 , Error (..) , Metadata
77 )
@@ -48,7 +48,7 @@ You could create entirely your own from scratch - maybe you want an http package
4848
4949# Expect
5050
51- @docs Expect, expectJson, expectString, expectBytes, expectWhatever, withMetadata
51+ @docs Expect, expectJson, expectString, expectBytes, expectRawBytes, expectWhatever, withMetadata
5252
5353
5454# Headers
@@ -88,7 +88,7 @@ type Body
8888type Expect a
8989 = ExpectJson ( Decoder a)
9090 | ExpectString ( Decoder a)
91- | ExpectBytes ( Bytes . Decode . Decoder a)
91+ | ExpectBytes ( Bytes -> Bytes . Decode . Decoder a)
9292 | ExpectWhatever ( Decoder a)
9393 | ExpectMetadata ( Metadata -> Expect a)
9494
@@ -238,8 +238,15 @@ expectString =
238238{- | Expect the response body to be `Bytes`, decode it using the supplied decoder.
239239-}
240240expectBytes : Bytes .Decode .Decoder a -> Expect a
241- expectBytes =
242- ExpectBytes
241+ expectBytes decoder =
242+ ExpectBytes ( \ _ -> decoder)
243+
244+
245+ {- | Expect the response body to be raw `Bytes`.
246+ -}
247+ expectRawBytes : Expect Bytes
248+ expectRawBytes =
249+ ExpectBytes Bytes . Decode . succeed
243250
244251
245252{- | Discard the response body.
@@ -261,7 +268,7 @@ withMetadata toMeta expect =
261268 ExpectMetadata ( \ meta -> ExpectString ( Decode . map ( toMeta meta) decoder))
262269
263270 ExpectBytes decoder ->
264- ExpectMetadata ( \ meta -> ExpectBytes ( Bytes . Decode . map ( toMeta meta) decoder))
271+ ExpectMetadata ( \ meta -> ExpectBytes ( \ raw -> Bytes . Decode . map ( toMeta meta) ( decoder raw ) ))
265272
266273 ExpectWhatever decoder ->
267274 ExpectMetadata ( \ meta -> ExpectWhatever ( Decode . map ( toMeta meta) decoder))
@@ -421,14 +428,14 @@ decodeJsonBody decoder meta =
421428 )
422429
423430
424- decodeBytesBody : Bytes .Decode .Decoder a -> Metadata -> Decoder (Result Error a )
431+ decodeBytesBody : ( Bytes -> Bytes .Decode .Decoder a ) -> Metadata -> Decoder (Result Error a )
425432decodeBytesBody decoder meta =
426433 Decode . string
427434 |> Decode . map
428435 ( \ res ->
429436 case Base64 . toBytes res of
430437 Just bytes ->
431- case Bytes . Decode . decode decoder bytes of
438+ case Bytes . Decode . decode ( decoder bytes ) bytes of
432439 Just a ->
433440 Ok a
434441
0 commit comments