seanmonstar / httparse

A push parser for the HTTP 1.x protocol in Rust.
https://docs.rs/httparse
Apache License 2.0
585 stars 114 forks source link

impl a function to parse chunk sizes #12

Closed pyfisch closed 8 years ago

pyfisch commented 8 years ago

All HTTP/1.1 clients and servers must understand the chunked encoding and therefore must parse chunk sizes. The parse_chunk_size function uses relies on the internals of httparse so it can't be implemented as easily in an external crate. It is based on hypers implementation but unlike hyper it operates on &[u8] and returns partial if the chunk size is incomplete. For this reason it is more suitable for async HTTP code.

This is a breaking change because it adds a new variant to the Error enum.

seanmonstar commented 8 years ago

Excellent, I've been meaning to do something like this.

I wonder if it makes sense to return httparse::Error from this function... The only error that could possibly happen is ChunkSize. Perhaps just make that pub struct InvalidChunkSize;? Would also mean it wouldn't be a breaking change...

pyfisch commented 8 years ago

It now uses pub struct InvalidChunkSize; so it is no longer a breaking change but the return type of parse_chunk_size is a lot less nice.