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

wrk incorrectly handles responses which contain no content-length header. #462

Open
ioquatix opened this issue Jul 28, 2021 · 0 comments · May be fixed by #463
Open

wrk incorrectly handles responses which contain no content-length header. #462

ioquatix opened this issue Jul 28, 2021 · 0 comments · May be fixed by #463

Comments

@ioquatix
Copy link

ioquatix commented Jul 28, 2021

static void socket_readable(aeEventLoop *loop, int fd, void *data, int mask) {
    connection *c = data;
    size_t n;

    do {
        switch (sock.read(c, &n)) {
            case OK:    break;
            case ERROR: goto error;
            case RETRY: return;
        }

        if (http_parser_execute(&c->parser, &parser_settings, c->buf, n) != n) goto error;
        if (n == 0 && !http_body_is_final(&c->parser)) goto error;

        c->thread->bytes += n;
    } while (n == RECVBUF && sock.readable(c) > 0);

    return;

  error:
    c->thread->errors.read++;
    reconnect_socket(c->thread, c);
}

In the case that you have a response like this:

HTTP/1.1 200 OK
Server: Cowboy
Date: Wed, 28 Jul 2021 10:49:43 GMT
Connection: close
Content-Type: text/plain
Vary: accept-encoding
Via: 1.1 vegur

Hello World!

The HTTP parser will enter the s_body_identity_eof state and http_body_is_final can never be true. So when you read EOF, http_body_is_final returns false, and it becomes error. But this is completely valid HTTP1.1 response.

It seems like in the above code http_parser_execute correctly handles this case, so the solution should be to delete the line if (n == 0 && !http_body_is_final(&c->parser)) goto error;.

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

Successfully merging a pull request may close this issue.

1 participant