Impl HEAD method
							parent
							
								
									9e3470d5b4
								
							
						
					
					
						commit
						aa183de15e
					
				|  | @ -109,10 +109,21 @@ async fn main () -> Result <(), Box <dyn Error>> { | |||
| 			} | ||||
| 		} | ||||
| 		
 | ||||
| 		let should_send_body = match &parts.method { | ||||
| 			http_serde::Method::Get => true, | ||||
| 			_ => false, | ||||
| 		}; | ||||
| 		
 | ||||
| 		println! ("Step 6"); | ||||
| 		let client = client.clone (); | ||||
| 		tokio::spawn (async move { | ||||
| 			let (tx, rx) = channel (2); | ||||
| 			let body = if should_send_body { | ||||
| 				Some (Body::wrap_stream (rx)) | ||||
| 			} | ||||
| 			else { | ||||
| 				None | ||||
| 			}; | ||||
| 			
 | ||||
| 			let mut path = PathBuf::from ("/home/user"); | ||||
| 				path.push (&uri [1..]); | ||||
|  | @ -124,6 +135,7 @@ async fn main () -> Result <(), Box <dyn Error>> { | |||
| 			
 | ||||
| 			let file_md = f.metadata ().await.unwrap (); | ||||
| 			
 | ||||
| 			if should_send_body { | ||||
| 			tokio::spawn (async move { | ||||
| 				//println! ("Opening file {:?}", path);
 | ||||
| 				
 | ||||
|  | @ -150,6 +162,7 @@ async fn main () -> Result <(), Box <dyn Error>> { | |||
| 					delay_for (Duration::from_millis (50)).await; | ||||
| 				} | ||||
| 			}); | ||||
| 			} | ||||
| 			
 | ||||
| 			let mut headers: HashMap <String, Vec <u8>> = Default::default (); | ||||
| 			//headers.insert (String::from ("x-its-a-header"), Vec::from (&b"wow"[..]));
 | ||||
|  | @ -163,10 +176,13 @@ async fn main () -> Result <(), Box <dyn Error>> { | |||
| 				headers, | ||||
| 			}; | ||||
| 			
 | ||||
| 			let resp_req = client | ||||
| 			let mut resp_req = client | ||||
| 			.post (&format! ("http://127.0.0.1:4000/http_response/{}", req_id)) | ||||
| 			.header ("X-PTTH-2LJYXWC4", base64::encode (rmp_serde::to_vec (&resp_parts).unwrap ())) | ||||
| 			.body (Body::wrap_stream (rx)); | ||||
| 			.header ("X-PTTH-2LJYXWC4", base64::encode (rmp_serde::to_vec (&resp_parts).unwrap ())); | ||||
| 			
 | ||||
| 			if let Some (body) = body { | ||||
| 				resp_req = resp_req.body (body); | ||||
| 			} | ||||
| 			
 | ||||
| 			println! ("Step 6"); | ||||
| 			if let Err (e) = resp_req.send ().await { | ||||
|  |  | |||
|  | @ -18,8 +18,8 @@ impl From <hyper::header::InvalidHeaderName> for Error { | |||
| 
 | ||||
| #[derive (Deserialize, Serialize)] | ||||
| pub enum Method { | ||||
| 	// Only GET is supported for now
 | ||||
| 	Get, | ||||
| 	Head, | ||||
| } | ||||
| 
 | ||||
| impl TryFrom <hyper::Method> for Method { | ||||
|  | @ -28,19 +28,12 @@ impl TryFrom <hyper::Method> for Method { | |||
| 	fn try_from (x: hyper::Method) -> Result <Self, Error> { | ||||
| 		match x { | ||||
| 			hyper::Method::GET => Ok (Self::Get), | ||||
| 			hyper::Method::HEAD => Ok (Self::Head), | ||||
| 			_ => Err (Error::Unsupported), | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| impl From <Method> for hyper::Method { | ||||
| 	fn from (x: Method) -> Self { | ||||
| 		match x { | ||||
| 			Method::Get => Self::GET, | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| #[derive (Deserialize, Serialize)] | ||||
| pub struct RequestParts { | ||||
| 	pub id: String, | ||||
|  | @ -61,25 +54,15 @@ pub struct RequestParts { | |||
| pub enum StatusCode { | ||||
| 	Ok, | ||||
| 	NotFound, | ||||
| 	PartialContent, | ||||
| } | ||||
| /* | ||||
| impl TryFrom <hyper::StatusCode> for StatusCode { | ||||
| 	type Error = Error; | ||||
| 	
 | ||||
| 	fn try_from (x: hyper::StatusCode) -> Result <Self, Error> { | ||||
| 		match x { | ||||
| 			hyper::StatusCode::OK => Ok (Self::Ok), | ||||
| 			hyper::StatusCode::NOT_FOUND => Ok (Self::NotFound), | ||||
| 			_ => Err (Error::Unsupported), | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| */ | ||||
| 
 | ||||
| impl From <StatusCode> for hyper::StatusCode { | ||||
| 	fn from (x: StatusCode) -> Self { | ||||
| 		match x { | ||||
| 			StatusCode::Ok => Self::OK, | ||||
| 			StatusCode::NotFound => Self::NOT_FOUND, | ||||
| 			StatusCode::PartialContent => Self::PARTIAL_CONTENT, | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 _
						_