标签: iron

使用带铁的防锈网箱

是否可以使用带铁的防锈网袋,或者将两者一起使用没有意义?

如果有可能,我怎么能意识到呢?

iron websocket rust

9
推荐指数
1
解决办法
1675
查看次数

如何发送include_bytes附带的文件!作为铁响应?

我正在尝试include_bytes!在Iron应用程序中发送包含在二进制文件中的文件.我想最终为我的应用程序提供一个文件,它只需要很少的HTML,CSS和JS文件.这是一个我正在摆弄的小型测试设置:

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::<Mime>().unwrap();
        Ok(Response::with((content_type, status::Ok, index_html)))
    }).http("localhost:8001").unwrap();
}
Run Code Online (Sandbox Code Playgroud)

当然,这种index_html类型不起作用&[u8; 78]

src/main.rs:16:12: 16:26 error: the trait `modifier::Modifier<iron::response::Response>` is not implemented for the type `&[u8; 78]` [E0277]
src/main.rs:16         Ok(Response::with((content_type, status::Ok, index_html)))
Run Code Online (Sandbox Code Playgroud)

由于我对Rust和Iron很新,我不知道如何处理这个问题.我试图从Iron文档中学到一些东西,但我认为我的Rust知识不足以真正理解它们,特别是这个modifier::Modifier特性应该是什么.

我怎样才能做到这一点?我可以将我的静态资源类型转换为Iron将接受的东西,或者我需要以Modifier某种方式实现此特征吗?

iron rust

5
推荐指数
1
解决办法
1543
查看次数

恐慌!不会停止Iron服务器

我想panic!在Rust中停止一切,但如果我panic!在Iron路由处理函数中它不会停止整个服务器.相反,它只显示恐慌信息.

这是"正常"行为panic!吗?

我没有发布我的实际代码,因为我不认为它在这里有用,但我可以根据需要添加它.

iron rust

5
推荐指数
1
解决办法
186
查看次数

如何配置 Iron 以侦听 Unix 域套接字?

我有一个来自ironframework.io 的简单示例:

extern crate iron;

use iron::prelude::*;
use iron::status;

fn main() {
    fn hello_world(_: &mut Request) -> IronResult<Response> {
        Ok(Response::with((status::Ok, "Hello World!")))
    }
    // below code
    let _server = Iron::new(hello_world).http("localhost:3000").unwrap(); 
    println!("On 3000");
}
Run Code Online (Sandbox Code Playgroud)

我希望服务器侦听 Unix 域套接字 (UDS)。

iron unix-socket rust

5
推荐指数
0
解决办法
171
查看次数

如何在中间件和处理程序中读取Iron请求?

我正在研究Rust中的一个小API,我不知道如何Request在两个地方访问Iron.

Authentication中间件读取Request一个令牌,一旦与实际路线试图如果路径是允许(目前还没有检查)看了一遍.这给了我一个EOF错误,因为已经读取了请求.

我似乎无法轻易克隆请求,我相信它必须是可变的才能阅读正文.

extern crate iron;
extern crate router;
extern crate rustc_serialize;

use iron::prelude::*;
use iron::{BeforeMiddleware, status};
use router::Router;
use rustc_serialize::json;
use rustc_serialize::json::Json;
use std::io::Read;

#[derive(RustcEncodable, RustcDecodable)]
struct Greeting {
    msg: String
}

struct Authentication;

fn main() {
    let mut request_body = String::new();

    impl BeforeMiddleware for Authentication {
        fn before(&self, request: &mut Request) -> IronResult<()> {
            let mut payload = String::new();
            request.body.read_to_string(&mut payload).unwrap();
            let json = Json::from_str(&payload).unwrap();

            println!("json: {}", json);

            let token = json.as_object() …
Run Code Online (Sandbox Code Playgroud)

middleware request iron rust

4
推荐指数
1
解决办法
1168
查看次数

Iron框架如何将一组修饰符应用于Response :: with?

我正在研究Iron源代码Response::with(),试图理解它如何将元组作为修饰符应用于响应.

据我所知,修饰符只是一个构建器对象,它引用当前上下文(self)并将您希望构建的对象作为参数(只要您实现该modify函数).

假设我们有以下代码:

use iron::modifiers::Header;

fn hello_world(_: &mut Request) -> IronResult<Response> {
    let string = get_file_as_string("./public/index.html");
    let content_type = Header(ContentType(Mime(TopLevel::Text, SubLevel::Html, vec![])));
    Ok(Response::with((status::Ok, string, content_type)))
}
Run Code Online (Sandbox Code Playgroud)

通过文档挖掘,我可以看到Response::with()Iron中的实现如下:

pub fn new() -> Response {
    Response {
        status: None, // Start with no response code.
        body: None, // Start with no body.
        headers: Headers::new(),
        extensions: TypeMap::new()
    }
}

/// Construct a Response with the specified modifier pre-applied.
pub fn with<M: Modifier<Response>>(m: M) -> Response …
Run Code Online (Sandbox Code Playgroud)

iron rust

4
推荐指数
1
解决办法
108
查看次数

IronPython Windows 7 pythonpath

在Windows 7上安装iropython后,有一个环境变量

PYTHONPATH=C:\Program Files (x86)\IronPython 2.7\Lib
Run Code Online (Sandbox Code Playgroud)

在Linux系统上众所周知的这个变量,我想将其扩展到文件夹c:\ user ... \ pymodules,我尝试使用

PYTHONPATH=C:\Program Files (x86)\IronPython 2.7\Lib:c:\user\...\pymodules
Run Code Online (Sandbox Code Playgroud)

PYTHONPATH=C:\Program Files (x86)\IronPython 2.7\Lib;c:\user\...\pymodules
Run Code Online (Sandbox Code Playgroud)

但是无论从哪方面来看我都没有成功

这个问题有什么解决办法吗

python environment iron windows-7 pythonpath

3
推荐指数
1
解决办法
1544
查看次数

静态可变数据的惯用替代方法是什么?

我正在使用 Iron 框架来创建一个简单的端点。我有端点需要访问的有状态的可变数据。

这是一些显示我意图的代码:

extern crate iron;
extern crate mount;

use iron::{Iron, Request, Response, IronResult};
use iron::status;
use mount::Mount;

static mut s_counter: Option<Counter> = None;

struct Counter {
    pub count: u8
}

impl Counter {
    pub fn new() -> Counter {
        Counter {
            count: 0
        }
    }

    pub fn inc(&mut self) {
        self.count += 1;
    }
}

fn main() {
    unsafe { s_counter = Some(Counter::new()); }
    let mut mount = Mount::new();
    mount.mount("/api/inc", inc);
    println!("Server running on http://localhost:3000");
    Iron::new(mount).http("127.0.0.1:3000").unwrap();
}

fn …
Run Code Online (Sandbox Code Playgroud)

iron rust

3
推荐指数
1
解决办法
883
查看次数

铁处理程序:缺少终身说明符

我正在尝试实现一个包含对另一个结构的引用的Iron处理程序.该结构保存数据并对数据执行所有操作.

[package]
name = "testcrate"
version = "0.1.0"
authors = ["me"]

[dependencies]
iron = "^0.2"
Run Code Online (Sandbox Code Playgroud)

这是代码:

//! Handlers for the server.
extern crate iron;

use iron::{status, middleware};
use iron::IronResult;
use iron::prelude::Set;
use iron::request::Request;
use iron::response::Response;

/// The MyServer struct holds the data and provides methods
/// to manipulate or retrieve that data.
struct MyServer;
impl MyServer {
    pub fn build_response() -> String {
        "response".to_string()
    }   
}

/// The ReadHandler handles the creation of HTTP responses.
pub struct ReadHandler {
    pub …
Run Code Online (Sandbox Code Playgroud)

lifetime iron rust

2
推荐指数
1
解决办法
269
查看次数

是否可以使用Iron框架在路由器位置发布JSON文件?

我在应用程序中使用Iron Web框架(用于Rust编程语言),并且在使用Router crate时我有一个暴露于POST JSON数据的路径.

它可以工作,但我必须对我的JSON数据进行百分比编码并将其作为字符串附加到我的HTTP POST请求的末尾 - 这有效,但有点乏味,我想最终POST原始图像文件.

我希望能够按照以下curl命令执行某些操作:

curl -v -i --header "Content-Type: application/json" -X POST -d @some_local_json_file.json http://my_server_ip_address:3000/example_path/post/json_object_here
Run Code Online (Sandbox Code Playgroud)

我目前收到一个HTTP/1.1 404 Not Found错误:

curl -v -i --header "Content-Type: application/json" -X POST -d @some_local_json_file.json http://my_server_ip_address:3000/example_path/post/json
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying my_server_ip_address...
* Connected to my_server_ip_address (my_server_ip_address) port 3000 (#0)
> POST /example_path/post/json HTTP/1.1
> Host: my_server_ip_address:3000
> User-Agent: curl/7.45.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 2354 …
Run Code Online (Sandbox Code Playgroud)

json iron rust

2
推荐指数
1
解决办法
543
查看次数