Skip to content

Commit

Permalink
Set max payload size
Browse files Browse the repository at this point in the history
Remove underscore on headers
  • Loading branch information
dormant-user committed Mar 13, 2024
1 parent bd1b8fc commit 6fd4c19
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ pub async fn start() -> io::Result<()> {
The closure is defining the configuration for the Actix web server.
The purpose of the closure is to configure the server before it starts listening for incoming requests.
*/
let max_payload_size = 10 * 1024 * 1024 * 1024; // 10 GB
let application = move || {
App::new() // Creates a new Actix web application
.app_data(web::Data::new(config_clone.clone()))
.app_data(web::Data::new(jinja.clone()))
.app_data(web::Data::new(fernet.clone()))
.app_data(web::Data::new(session.clone()))
.app_data(web::PayloadConfig::default().limit(max_payload_size))
.wrap(squire::middleware::get_cors(config_clone.websites.clone()))
.wrap(middleware::Logger::default()) // Adds a default logger middleware to the application
.service(routes::basics::health) // Registers a service for handling requests
Expand Down
4 changes: 2 additions & 2 deletions src/routes/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pub async fn save_files(request: HttpRequest,
}
let mut upload_path = config.media_source.clone(); // cannot be borrowed as mutable
let mut secure_str = "";
if let Some(dedicated) = request.headers().get("dedicated_directory") {
if dedicated.to_str().unwrap_or("false") == "true" {
if let Some(secure_flag) = request.headers().get("secure-flag") {
if secure_flag.to_str().unwrap_or("false") == "true" {
secure_str = "to secure index ";
upload_path.extend([format!("{}_{}", &auth_response.username, constant::SECURE_INDEX)])
}
Expand Down
2 changes: 1 addition & 1 deletion src/squire/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn get_cors(websites: Vec<String>) -> Cors {
let mut cors = Cors::default()
.allowed_methods(vec!["GET", "POST"])
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT, header::CONTENT_TYPE])
.allowed_header("dedicated_directory")
.allowed_header("secure-flag")
.max_age(3600); // Maximum time (in seconds) for which this CORS request may be cached
for origin in origins {
cors = cors.allowed_origin(&origin);
Expand Down
2 changes: 1 addition & 1 deletion src/templates/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ pub fn get_content() -> String {
li.querySelectorAll('span')[1].style.width = percent_complete + '%'
}
http.open('POST', window.location.origin + '/upload', true); // asynchronous session
http.setRequestHeader('dedicated_directory', checkbox.checked);
http.setRequestHeader('secure-flag', checkbox.checked);
http.send(data)
li.querySelector('.cross').onclick = () => http.abort()
http.onabort = () => {
Expand Down

0 comments on commit 6fd4c19

Please sign in to comment.