idris-http icon indicating copy to clipboard operation
idris-http copied to clipboard

Chunked Encoding doesn't work yet

Open uwap opened this issue 10 years ago • 2 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?

uwap avatar Aug 23 '15 15:08 uwap

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: https://github.com/uwap/idris-http/blob/dc4a31543f87c0bc44cbaa98192f0303cd8dd82e/src/Http/Response.idr#L71

*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.

hackle avatar Dec 26 '18 03:12 hackle

@hackle thanks

uwap avatar Dec 26 '18 11:12 uwap