diff --git a/src/Network/HTTP/Scheduler.idr b/src/Network/HTTP/Scheduler.idr index 0434d6e..6399cc5 100644 --- a/src/Network/HTTP/Scheduler.idr +++ b/src/Network/HTTP/Scheduler.idr @@ -10,6 +10,8 @@ import Data.List1 import Data.Compress.Interface import Data.Compress.GZip import Data.Compress.ZLib +import Data.String +import System.Concurrency public export record ScheduleResponse (e : Type) (m : Type -> Type) where @@ -34,16 +36,23 @@ interface Scheduler (e : Type) (m : Type -> Type) (0 a : Type) where channel_to_stream : (HasIO m, Decompressor c) => c -> Channel (Either (HttpError e) (Maybe (List Bits8))) -> Stream (Of Bits8) m (Either (HttpError e) ()) channel_to_stream decomp channel = do - Right (Just content) <- liftIO $ channelGet channel - | Right Nothing => + putStrLn "Asking for data" + result <- liftIO $ channelGet channel + putStrLn "Asked for data" + case result of + Right (Just content) => do + putStrLn $ "got " ++ show content + let Right (decompressed, newDecomp) = feed decomp content + | Left err => pure (Left $ DecompressionError err) + fromList_ decompressed *> channel_to_stream newDecomp channel + Right Nothing => do + putStrLn "Got nothing" case done decomp of Right [] => pure (Right ()) Right xs => pure (Left $ DecompressionError "\{show $ length xs} leftover bytes in decompression buffer") Left err => pure (Left $ DecompressionError err) - | Left err => pure (Left err) - let Right (content, decomp) = feed decomp content - | Left err => pure (Left $ DecompressionError err) - fromList_ content *> channel_to_stream decomp channel + Left err => pure (Left err) + decompressor : List ContentEncodingScheme -> DPair Type Decompressor decompressor [ GZip ] = MkDPair GZipState %search diff --git a/src/Test.idr b/src/Test.idr new file mode 100644 index 0000000..564d320 --- /dev/null +++ b/src/Test.idr @@ -0,0 +1,27 @@ +module Test + +import Data.Nat +import Network.HTTP +import Control.Monad.Error.Either +import Control.Monad.Error.Interface + +ResultMonad : Type -> Type +ResultMonad = EitherT (HttpError ()) IO + +getClient: IO (HttpClient ()) +getClient = new_client certificate_ignore_check 1 1 False False + +performRequest : HttpClient () -> ResultMonad (HttpResponse, Stream (Of Bits8) ResultMonad ()) +performRequest client = + request client GET (url' "https://anglesharp.azurewebsites.net/Chunked") [("Authorization", "Bearer foo")] () + +silly_me = do + client <- getClient + Right (result, stream) <- runEitherT $ performRequest client + | Left e => printLn $ "Error from calling url " ++ show e + putStrLn $ show result + Right (content, _) <- runEitherT $ toList stream + | Left e => printLn $ "Error from reading response stream " ++ show e + putStrLn $ show content + putStrLn "Done" + close client \ No newline at end of file