Skip to content
Open
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
25 changes: 9 additions & 16 deletions demo_format.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use actix_files::Files;
use actix_multipart::Multipart;
use actix_web::{
get, middleware::Logger,
post, web,
App, Error, HttpResponse, HttpServer, Responder,
get, middleware::Logger, post, web, App, Error, HttpResponse, HttpServer, Responder,
};

use futures_util::stream::StreamExt as _;
Expand All @@ -19,23 +17,20 @@ use std::os::windows::fs::MetadataExt;

#[get("/{route}")]
async fn index_routes() -> impl Responder {
HttpResponse::Ok()
.body(read("./build/index.html")
.unwrap())
HttpResponse::Ok().body(read("./build/index.html").unwrap())
}

#[get("/")]
async fn index() -> impl Responder {
HttpResponse::Ok()
.body(read("./build/index.html").unwrap())
HttpResponse::Ok().body(read("./build/index.html").unwrap())
}

#[post("/upload/")]
async fn upload(mut payload: Multipart) -> Result<HttpResponse, Error> {
// iterate over multipart stream
log::warn!("/upload/ was called!");
while let Some(Ok(mut field)) = payload.next().await {
// A multipart/form-data stream has to contain `content_disposition`
// A multipart/form-data stream has to contain `content_disposition`
let content_disposition = field.content_disposition();
let filename = content_disposition
.get_filename()
Expand All @@ -47,8 +42,8 @@ async fn upload(mut payload: Multipart) -> Result<HttpResponse, Error> {

// Field in turn is stream of *Bytes* object
while let Some(Ok(chunk)) = field.next().await {
// filesystem operations are blocking, we have to use threadpool
f = web::block(move || f.write_all(&chunk).map(|_| f)).await??;
// filesystem operations are blocking, we have to use threadpool
f = web::block(move || f.write_all(&chunk).map(|_| f)).await??;
}
}

Expand Down Expand Up @@ -95,7 +90,6 @@ async fn main() -> std::io::Result<()> {
.await
}


use cookie::{Cookie, CookieJar};

fn use_cookie_without_secure() {
Expand All @@ -116,14 +110,13 @@ fn use_cookie_without_http_only() {
}

fn use_cookie_builder_without_http_only() {
Cookie::build("name",
"value").http_only(true);
Cookie::build("name", "value").http_only(true);
Cookie::build("name", "value").http_only(false);
}

fn header() {
use http::header::{HeaderMap, SERVER, SET_COOKIE};
let mut h = HeaderMap::new();
use http::header::{HeaderMap, SERVER, SET_COOKIE};
let mut h = HeaderMap::new();
h.insert(SERVER, 5.into());
h.insert(SET_COOKIE, 42.into());
}
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ fn main() {
if false {
// this is untouched comment, this is untouched comment
// this is untouched comment
} print!("main");
}
print!("main");
bar();
}

Expand Down