seanmonstar / httparse

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

Beginner Issue : req.parse "Accept-Encoding" header produces Version error #171

Closed icecloud12 closed 5 months ago

icecloud12 commented 5 months ago

Tagged as beginner for it might be a stupid question

req.parse function with the Accept-Encoding section produces a Version error.

I created a post request using postman and got the stream data using tcplistener->tcpstream, converted them to bytes etc..

let buf = b"POST /index.html HTTP/1.1\r\n";
println!("{:#?}", req.parse(buf));
...
println!("{:#?}", req.parse(buf));
  let buf = b"Accept-Encoding: gzip, deflate, br"; 
println!("{:#?}", req.parse(buf)); //error occurs here
...

using current version 1.9.2 attaching sample input generated by postman sampleInput.txt

I am an absolute beginner so this might not be an issue sorry for taking your time

seanmonstar commented 5 months ago

httparse is stateless, so every call to parse(buf) must be with a buffer that represents an HTTP message. Such as "POST /index.html HTTP/1.1\r\nAccept-Encoding: gzip, deflate, br\r\n\r\n".