iron

How do I read an Iron Request in both middleware and the handler?

为君一笑 提交于 2020-01-03 16:46:12
问题 I'm working on a small API in Rust and am not sure how to access a Request from Iron in two places. The Authentication middleware reads the Request once for a token and the actual route tries to read it again if the path is allowed (currently there is no check). This gives me an EOF error as the request has already been read. I can't seem to easily clone the request and I believe it must be mutable in order to read the body. extern crate iron; extern crate router; extern crate rustc_serialize

How to change Iron's default 404 behaviour?

冷暖自知 提交于 2019-12-26 13:35:28
问题 I want to change the default 404 behaviour in a small Iron application. I want to add some simple text content to it, nothing complicated like using templates. 回答1: Iron has an example for how to do this. Create and start your program on an iron::Chain , and then create an iron::middleware::AfterMiddleware . This middleware could look like: fn custom_404(req: &mut Request, res: &mut Response) -> IronResult<Response> { if response.status == Some(Status::NotFound) { // Create a response as

How to change Iron's default 404 behaviour?

这一生的挚爱 提交于 2019-12-26 13:29:28
问题 I want to change the default 404 behaviour in a small Iron application. I want to add some simple text content to it, nothing complicated like using templates. 回答1: Iron has an example for how to do this. Create and start your program on an iron::Chain , and then create an iron::middleware::AfterMiddleware . This middleware could look like: fn custom_404(req: &mut Request, res: &mut Response) -> IronResult<Response> { if response.status == Some(Status::NotFound) { // Create a response as

Cannot access parameters in Iron because the trait bound plugin::Plugin<iron::Request> is not satisfied

戏子无情 提交于 2019-12-24 00:57:36
问题 I am exploring the capabilities of the Iron web framework. As far as I have figured out, the Iron core doesn't have an API to handle HTTP parameters so I tried to use the params crate. error: the trait bound `params::Params: plugin::Plugin<iron::Request<'_, '_>>` is not satisfied [E0277] let map = req.get_ref::<Params>().unwrap(); ^~~~~~~ help: run `rustc --explain E0277` to see a detailed explanation I haven't found trace of this bug and don't have a clue how to fix it. extern crate iron;

Nested Iron Ajax

自古美人都是妖i 提交于 2019-12-13 03:34:37
问题 Ok. So my last post was too ambiguous. For my second post, let me try to approach the same problem in hopefully a little more straighforward manner. Below is the code. Here is a screenshot of the results I get. Regarding the second iron-ajax call, if I use curl in terminal with this () I get what I want (it's a link preview service, so title, img, desc etc). Trying to accomplish the same with iron-ajax post with required parameters defined per spec. I don't get any console errors (for the

BeforeMiddleware implementation requires core::ops::Fn implementation

我的梦境 提交于 2019-12-12 03:36:38
问题 I am trying to implement the BeforeMiddleware trait for a struct I have. I have written the following code: impl BeforeMiddleware for Auth { fn before(&self, _: &mut Request) -> IronResult<()> { println!("before called"); Ok(()) } fn catch(&self, _: &mut Request, err: IronError) -> IronResult<()> { println!("catch called"); Err(err) } } I am getting the following error: > cargo build ... src/handlers/mod.rs:38:11: 38:28 error: the trait `for<'r, 'r, 'r> core::ops::Fn<(&'r mut iron::request:

Can't capture dynamic environment in a fn item about iron lib

て烟熏妆下的殇ゞ 提交于 2019-12-11 08:26:28
问题 I use the cassandra of the c/c++ driver to query, and then return the data. Therefore, both cass (LinkedList) and cass_it (Vec) can show the result of the query. However, I want to display the results to the web using the json format, so I chose to reassemble the data using vec. However, there is a problem: error[E0434]: can't capture dynamic environment in a fn item --> src/main.rs:306:42 | 306 | let out = serde_json::to_string(&cass_it).unwrap(); | ^^^^^^^ | = help: use the `|| { ... }`

Unable to compile Iron example: expected struct `iron::request::Request`, found struct `iron::Request`

廉价感情. 提交于 2019-12-11 06:59:58
问题 I'm trying to get a simple Iron example to work: extern crate iron; extern crate router; use iron::prelude::*; use iron::status; use router::Router; fn main() { let mut router = Router::new(); router.get("/controller", controller); fn controller(_: &mut Request) -> IronResult<Response> { Ok(Response::with((status::Ok, "Hello World!"))) } Iron::new(router).http("localhost:3000").unwrap(); } I maintain the following Cargo.toml: [package] name = "simple_router" version = "0.1.0" authors = [

Cannot create an Iron handler because the trait bound std::ops::Fn<(&mut iron::Request)> is not satisfied

时光毁灭记忆、已成空白 提交于 2019-12-11 03:25:56
问题 I'm trying to create a handler for Iron requests: extern crate iron; extern crate mount; use iron::{Iron, Request, Response, IronResult, status}; use mount::Mount; use iron::middleware::Handler; struct Server { message: String } impl Server { pub fn start(&self){ let mut mount = Mount::new(); mount.mount("/", &self); Iron::new(mount).http("0.0.0.0:3000").unwrap(); } } impl Handler for Server { fn handle(&self, _req: &mut Request) -> IronResult<Response>{ Ok(Response::with((status::Ok, self

How do I send a file included with include_bytes! as an Iron response?

你说的曾经没有我的故事 提交于 2019-12-10 13:44:54
问题 I'm trying to send a file that I included in the binary with include_bytes! in an Iron application. I want to end up with a single file for my application and it only needs very few HTML, CSS and JS files. Here's a small test setup that I'm fiddling with: extern crate iron; use iron::prelude::*; use iron::status; use iron::mime::Mime; fn main() { let index_html = include_bytes!("static/index.html"); println!("Hello, world!"); Iron::new(| _: &mut Request| { let content_type = "text/html".parse