actix-net icon indicating copy to clipboard operation
actix-net copied to clipboard

how to close connection immediately?

Open lithbitren opened this issue 2 years ago • 1 comments

if client's connection of actix-web is probably attacking, how can I close it immediately and insert the address into a dynamic blocklist?

when a addr is in the blocklist, i don't what to parse the uri or headers from this addr, just close the connection without sending or receiving any of the message.

    let listener = TcpListener::bind(...).await?;

    while let (socket, addr) = listener.accept().await? {

        if blocklist.contains(&addr) {
            continue;
        }

        tokio::spawn(async move {

            ...

            if connection_is_attacking() {
                blocklist.insert(addr);
                connection.close_immediately();
            }

            ...

        });
    }

lithbitren avatar Dec 06 '22 16:12 lithbitren