return 0 from `http_data(struct http_roundtripper*, const char*, int size, int*)` when `size` is 0?
Hi, Thanks for this project!
Sometimes servers send responses without Content-Length and expect the client to consume input (for the body) until EOF. Basically renders recv to return 0 before the parser decides the stream is complete, which will result in an error.
int ndata = recv(conn, buffer, sizeof(buffer), 0);
if (ndata <= 0) {
fprintf(stderr, "Error receiving data\n");
http_free(&rt);
close(conn);
return -1;
}
I wonder if this would be resolved by simply return 0 from http_data is the third parameter is passed as 0, i.e. EOF.
Hi, I discoverd the same issue while receiving a HTTP 304 response, because the response must not contain a body.
http_date(..) already does recognize responses without Content-Length and sets state http_roundtripper_unknown_data, but the state won't be entered due to while(size){..} and size is 0, even if size==0 is handled in this state.
To work around this issue and be able to enter the state http_roundtripper_unknown_data, I've changed the while statement in http_date(..).
int http_data(struct http_roundtripper* rt, const char* data, int size, int* read)
{
const int initial_size = size;
while ( size
|| (http_roundtripper_unknown_data == rt->state) ) {..}
}