Chunked Encoding doesn't work yet
uwap opened this issue · comments
When it comes to transfer encodings idris-http lacks a lot of features. Chunked Encoding is a special case that needs special review. With chunked encoding we are bound to counting bytes. The String type doesn't have the ability to check a length in bytes. That is a huge problem.
Idea 1: ByteString
We could just start making a ByteString library to support it. We would have one large problem with it: We would need to get TCP libraries to use them. Then chunked encoding wouldn't be too much magic here.
Idea 2: Do awkward requests
We could start reqeusting single bytes over TCP and then finally when we get to chunked encoding we request the nujmber of bytes of the next chunk. This is an awful implementation that I wouldn't like to support.
Are there any other ways to go?
Hi - I used idris-http
for a bit of play and found chunked encoding is not working as expected, because the current hexParser
might not return the correct number, Try the below if ever needed:
hexParser : Parser Int
hexParser = do { x <- hexParser'; pure $ fst x } where
hexParser' : Parser (Int, Int)
hexParser' = do
c <- hexDigit
hex2 <- opt $ hexParser'
let hex = ord $ toUpper c
let num = if hex >= ord '0' && hex <= ord '9'
then hex - ord '0'
else 10 + hex - ord 'A'
case hex2 of
Just (x, pw) =>
let pw' = pw + 1;
mag = Prelude.pow 16 $ cast {to=Nat} pw' in
pure (x + num * mag, pw')
Nothing => pure (num, 0)
With current hexParser:
idris-http/src/Http/Response.idr
Line 71 in dc4a315
*Parsers> parse hexParser "A0"
Right 0 : Either String Int
Sorry I should have started a PR couldn't at this moment so think it's best to report the issue first.