Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return 0 from http_data(struct http_roundtripper*, const char*, int size, int*) when size is 0? #8

Open
bl4ck5un opened this issue Apr 13, 2017 · 1 comment

Comments

@bl4ck5un
Copy link

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.

@JWebEmbDev
Copy link

JWebEmbDev commented May 25, 2023

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) ) {..}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants