Skip to content

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

Open
@ioquatix

Description

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;.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions