SizeLimitMiddleware
struct SizeLimitMiddleware
Middleware for limiting the request payload size.
If the incoming request does not contain the Content-Length
header, it
will return LENGTH_REQUIRED
status code.
Example
nv
use std.net.http.server.{
middlewares.SizeLimitMiddleware,
Router,
};
let app = Router.new().with(SizeLimitMiddleware.new(1024));
Implementions
Methods
new
pub fn new(max_size: int): SizeLimitMiddleware
[src]
pub fn new(max_size: int): SizeLimitMiddleware {
return SizeLimitMiddleware { max_size };
}
Creates a new SizeLimit
middleware.
new
pub fn new(max_size: int): SizeLimitMiddleware
[src]
pub fn new(max_size: int): SizeLimitMiddleware {
return SizeLimitMiddleware { max_size };
}
Creates a new SizeLimit
middleware.
Creates a new SizeLimit
middleware.
[src]
pub fn transform(self, handler: Handler): Handler {
return handler
.around(|handler, request| {
if (let content_length = request.headers().get("content-length")) {
if (let content_length_int = content_length.parse_int()) {
if (content_length_int > self.max_size) {
throw HttpError
.new(http.PayloadTooLarge, "Sized Limit Error: Payload Too Large");
} else {
return try handler.handle(request);
}
}
}
throw HttpError.new(http.LengthRequired, "Sized Limit Error: Missing Content Length");
});
}
[src]
pub fn transform(self, handler: Handler): Handler {
return handler
.around(|handler, request| {
if (let content_length = request.headers().get("content-length")) {
if (let content_length_int = content_length.parse_int()) {
if (content_length_int > self.max_size) {
throw HttpError
.new(http.PayloadTooLarge, "Sized Limit Error: Payload Too Large");
} else {
return try handler.handle(request);
}
}
}
throw HttpError.new(http.LengthRequired, "Sized Limit Error: Missing Content Length");
});
}