Skip to content

Hyper returns status 431 instead of 414 if url overflows max_buf_size #3874

Open
@jiahaoliang

Description

@jiahaoliang

Version
Hyper 0.14.30

Platform
ALL

Description

In my user case I use hyper as server and config it with a fixed http1_max_buf_size

hyper::Server::builder(incoming)
        .http1_max_buf_size(64 * 1024)
        ..serve(hyper::service::make_service_fn(... )

If the incomming url is greater than 64k, hyper returns 431 Request Header Fields Too Large instead of 414 URL TOO LONG. And since hyper will close connection afterwards, my service_fn is unable to catch this exception.(Or maybe it's possible but I just don't know how to)

I inspected the code briefly and found out the problem is here: here

if url overflows max_buf_size hyper just returns Error::new_too_large() and parsed as 431 Request Header Fields Too Large

I also inspect the parse_headers() implememtation, it seems that hyper must consume the whole buf to parse both request line and headers correctly. If the buf overflows, the current implemementation is unable to tell the difference between url too long or header too large.

I am wondering if this is a bug or any special consideration for the current implemementation/

[code sample that causes the bug]

I expected to see this happen: 414 URL TOO LONG

Instead, this happened: 431 Request Header Fields Too Large

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug. Something is wrong. This is bad!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions