Server configurations
Buffer size
The default buffer size to read/write from stream is 8096
bytes. You can specify buffer size in the Server
instance.
Form constraints
These constraints are automatically applied when you call request.parse()
method.
// These form constraints are the default form constraints used while parsing form body.
// Modify according to your need. All size are in bytes.
let form_constraints = FormConstraints::new(
512 * 1024 * 1024, // Max body size
2 * 1024 * 1024, // Max header size
512 * 1024 * 1024, // Max file size
2 * 1024 * 1024, // Max text value size
HashMap::new() // Field sizes by their names
);
let server = Server::bind("127.0.0.1:8080")
.form_constraints(form_constraints)
.urls(...)
.run()
.await;
Request constraints
These constraints are automatically applied while reading incoming requests from the client.
This will return Request Header Field Too Large
status response if header size is too large than the size specified in constraint.
// These request constraints are used while reading requests header.
let request_constraints = RequestConstraints {
max_request_header_size: 5 * 1024 * 1024, // Maximum allowed header size in bytes
max_header_count: 100, // Maximum number of headers allowed
};
let server = Server::bind("127.0.0.1:8080")
.request_constraints(request_constraints)
.urls(...)
.run()
.await;
TCP Nodelay
To set nodelay for socket client streams, use server.nodelay()
method. This configuration will do nothing
if you are using Unix Domain Socket.