Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): upload limit #348

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ pub mod mime;
/// Helper functions.
pub mod util;

/// Custom middleware implementation.
pub mod middleware;

// Use macros from tracing crate.
#[macro_use]
extern crate tracing;
Expand Down
24 changes: 22 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use actix_multipart::form::MultipartFormConfig;
use actix_multipart::MultipartError;
use actix_web::middleware::Logger;
use actix_web::web::Data;
use actix_web::Error;
use actix_web::HttpRequest;
use actix_web::{App, HttpServer};
use awc::ClientBuilder;
use byte_unit::Byte;
use hotwatch::notify::event::ModifyKind;
use hotwatch::{Event, EventKind, Hotwatch};
use rustypaste::config::{Config, ServerConfig};
use rustypaste::middleware::ContentLengthLimiter;
use rustypaste::paste::PasteType;
use rustypaste::server;
use rustypaste::util;
Expand All @@ -25,6 +29,11 @@ use tracing_subscriber::{
#[macro_use]
extern crate tracing;

fn handle_multipart_error(err: MultipartError, _req: &HttpRequest) -> Error {
error!("Multipart error: {}", err);
Error::from(err)
}

/// Sets up the application.
///
/// * loads the configuration
Expand Down Expand Up @@ -172,10 +181,21 @@ async fn main() -> IoResult<()> {
App::new()
.app_data(Data::clone(&config))
.app_data(Data::new(http_client))
.app_data(
MultipartFormConfig::default()
.total_limit(
Byte::parse_str(&server_config.max_content_length, true)
.expect("cannot parse byte")
.as_u64()
.try_into()
.unwrap(),
)
.memory_limit(10 * 1024 * 1024)
.error_handler(handle_multipart_error),
)
.wrap(Logger::new(
"%{r}a \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\" %T",
))
.wrap(ContentLengthLimiter::new(server_config.max_content_length))
.configure(server::configure_routes)
})
.bind(&server_config.address)?;
Expand Down
96 changes: 0 additions & 96 deletions src/middleware.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ pub fn configure_routes(cfg: &mut web::ServiceConfig) {
mod tests {
use super::*;
use crate::config::LandingPageConfig;
use crate::middleware::ContentLengthLimiter;
use crate::random::{RandomURLConfig, RandomURLType};
use actix_web::body::MessageBody;
use actix_web::body::{BodySize, BoxBody};
Expand Down
Loading