mirror of
				https://github.com/balkian/experiments.git
				synced 2025-10-31 15:48:24 +00:00 
			
		
		
		
	first commit
This commit is contained in:
		
							
								
								
									
										1712
									
								
								rust/actix/Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										1712
									
								
								rust/actix/Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										13
									
								
								rust/actix/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								rust/actix/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| [package] | ||||
| name = "actixtest" | ||||
| version = "0.1.0" | ||||
| authors = ["J. Fernando Sánchez <balkian@gmail.com>"] | ||||
| edition = "2018" | ||||
|  | ||||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||||
|  | ||||
| [dependencies] | ||||
| actix-web = "1.0.9" | ||||
| actix-service = "0.4.2" | ||||
| futures = "0.1.29" | ||||
| #actix-http = "1.0.0" | ||||
							
								
								
									
										20
									
								
								rust/actix/src/main-old.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								rust/actix/src/main-old.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| use futures::future::Future; | ||||
| use actix_service::Service; | ||||
| use actix_web::{web, App}; | ||||
| use actix_web::http::{header::CONTENT_TYPE, HeaderValue}; | ||||
|  | ||||
|  | ||||
| fn main() { | ||||
|     let app = App::new() | ||||
|         .wrap_fn(|req, srv| | ||||
|                  srv.call(req).map(|mut res| { | ||||
|                      res.headers_mut().insert( | ||||
|                          CONTENT_TYPE, HeaderValue::from_static("text/plain"), | ||||
|                      ); | ||||
|                      res | ||||
|                  })) | ||||
|         .route( | ||||
|             "/index.html", | ||||
|             web::get().to(|| "Hello, middleware!"), | ||||
|         ); | ||||
| } | ||||
							
								
								
									
										45
									
								
								rust/actix/src/main.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								rust/actix/src/main.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,45 @@ | ||||
| use futures::future::Future; | ||||
| use actix_service::{Service}; | ||||
| use actix_web::{web, App, HttpRequest, HttpServer, Responder}; | ||||
| use actix_web::http::{header::CONTENT_TYPE, HeaderValue}; | ||||
|  | ||||
|  | ||||
| fn greet(req: HttpRequest) -> impl Responder { | ||||
|     let name = req.match_info().get("name").unwrap_or("World"); | ||||
|     format!("Hello {}!", &name) | ||||
|  | ||||
| } | ||||
|  | ||||
| fn p404(req: HttpRequest) -> impl Responder { | ||||
|     println!("{:?}", req); | ||||
|     actix_web::HttpResponse::NotFound() | ||||
|        .content_type("text/plain") | ||||
|        .body("Thou shall not pass") | ||||
|  | ||||
| } | ||||
|  | ||||
|  | ||||
| fn main() { | ||||
|     HttpServer::new(|| { | ||||
|         App::new() | ||||
|             .route("/", web::get().to(greet)) | ||||
|             .route("/{name}", web::get().to(greet)) | ||||
|             .default_service( | ||||
|                 web::route().to(p404)) | ||||
|             .wrap_fn(|req, srv| { | ||||
|                 println!("{:?}", req); | ||||
|                 srv.call(req).map(|mut res| { | ||||
|                     res.headers_mut().insert( | ||||
|                         CONTENT_TYPE, | ||||
|                         HeaderValue::from_static("0001"), | ||||
|                         ); | ||||
|                     res | ||||
|                 }) | ||||
|             }) | ||||
|     }) | ||||
|         .bind("127.0.0.1:8000") | ||||
|         .expect("Can not bind to port 8000") | ||||
|         .run() | ||||
|         .unwrap(); | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user