Git Product home page Git Product logo

body-parser's People

Contributors

aerialx avatar brycefisher avatar chritchens avatar dbrgn avatar emberian avatar fauxfaux avatar fuchsnj avatar jimmycuadra avatar keydunov avatar lukaskalbertodt avatar reem avatar s-panferov avatar skylerlipthay avatar theptrk avatar trotter avatar uniphil avatar untitaker avatar zzmp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

body-parser's Issues

Compilation fails on rust nightly

Compiling fails using rust nightly, the allowed syntax for extern crate seems to be different now:

[...]
Compiling bodyparser v0.0.4 (file:///home/niclas/Hacks/rust/body-parser)
src/lib.rs:9:14: 9:31 error: expected ident, found `"rustc-serialize"`
src/lib.rs:9 extern crate "rustc-serialize" as rustc_serialize;
                          ^~~~~~~~~~~~~~~~~
Could not compile `bodyparser`.

Iron's Request has no method get

I just copied the code from the readme, and it looks like the example is outdated. This is the error I get.

src/server.rs:38:15: 38:49 error: type `&mut iron::request::Request` does not implement any method in scope named `get`
src/server.rs:38     match req.get::<BodyParser<PleaseCompile>>() {
                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Also, the link to the docs is dead...

Suport for iron 0.6

Iron 0.6 has been released.

Are you already working on migration or I should fork and provide the migration?

does not compile with latest Rust nightly

   Compiling bodyparser v0.0.5
/home/nathan/.cargo/registry/src/github.com-1ecc6299db9ec823/bodyparser-0.0.5/src/lib.rs:9:14: 9:31 error: expected ident, found `"rustc-serialize"`
/home/nathan/.cargo/registry/src/github.com-1ecc6299db9ec823/bodyparser-0.0.5/src/lib.rs:9 extern crate "rustc-serialize" as rustc_serialize;
                                                                                                        ^~~~~~~~~~~~~~~~~
rustc --version
rustc 1.0.0-nightly (abf0548b5 2015-04-15) (built 2015-04-16)

Proposal: BodyParser Should Change Contract

Currently body parser works by returning a Result<Option>:

    let struct_body = req.get::<bodyparser::Struct<MyStructure>>();
    match struct_body {
        Ok(Some(struct_body)) => println!("Parsed body:\n{:?}", struct_body),
        Ok(None) => println!("No body"),
        Err(err) => println!("Error: {:?}", err)
    }

I believe that adding an Option to the return type forces the consumer to have an extra level of matching for no gained benefit (in my personal opinion).

If I am trying to parse a body and there is no body present, I would argue that it should be an Err, instead of being Ok(None), after all, I was expected a value to be there that is missing. You can add MissingBody as a potential error code.

I believe this would simplify the API and make it easier to consume.

If the maintainers of this repo agree with my proposal, I can go ahead and submit a PR.

Thanks.

compilation error: can't find crate for 'plugin'

   Compiling bodyparser v0.0.1
     Running `rustc /home/xav/.cargo/registry/src/github.com-1ecc6299db9ec823/bodyparser-0.0.1/src/lib.rs --crate-name bodyparser --crate-type lib -g -C metadata=6d3d4ec3aa702856 -C extra-filename=-6d3d4ec3aa702856 --out-dir /home/xav/toysarust/target/deps --emit=dep-info,link -L dependency=/home/xav/toysarust/target/deps -L dependency=/home/xav/toysarust/target/deps --extern iron=/home/xav/toysarust/target/deps/libiron-cd5b38656a4d68ab.rlib -Awarnings -L native=/usr/lib/x86_64-linux-gnu -L native=/home/xav/toysarust/target/build/time-24f9c2dbbbc6f19b/out`
/home/xav/.cargo/registry/src/github.com-1ecc6299db9ec823/bodyparser-0.0.1/src/lib.rs:2:12: 2:31 warning: feature has been added to Rust, directive not necessary
/home/xav/.cargo/registry/src/github.com-1ecc6299db9ec823/bodyparser-0.0.1/src/lib.rs:2 #![feature(default_type_params)]
                                                                                                   ^~~~~~~~~~~~~~~~~~~
/home/xav/.cargo/registry/src/github.com-1ecc6299db9ec823/bodyparser-0.0.1/src/lib.rs:2:12: 2:31 warning: feature has been added to Rust, directive not necessary
/home/xav/.cargo/registry/src/github.com-1ecc6299db9ec823/bodyparser-0.0.1/src/lib.rs:2 #![feature(default_type_params)]
                                                                                                   ^~~~~~~~~~~~~~~~~~~
/home/xav/.cargo/registry/src/github.com-1ecc6299db9ec823/bodyparser-0.0.1/src/lib.rs:10:1: 10:21 error: can't find crate for `plugin`
/home/xav/.cargo/registry/src/github.com-1ecc6299db9ec823/bodyparser-0.0.1/src/lib.rs:10 extern crate plugin;
                                                                                         ^~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
Could not compile `bodyparser`.

Can't compile with rust nightly (built 2015-03-05)

I cloned this repository and tried to cargo build it, but it fails:

    src/lib.rs:30:37: 30:45 error: type `iron::request::Body<'_>` does not implement any method in scope named `by_ref`
    src/lib.rs:30     match LimitReader::new(req.body.by_ref(), limit).read_to_end() {
                                                      ^~~~~~~~
    src/lib.rs:30:45: 30:45 help: methods from traits can only be called if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
    src/lib.rs:30:45: 30:45 help: candidate #1: use `std::io::ReadExt`
    error: aborting due to previous error
    Could not compile `bodyparser`.

Version:

$ rustc -V
rustc 1.0.0-nightly (3b3bb0e68 2015-03-04) (built 2015-03-05)
$ cargo -V
cargo 0.0.1-pre-nightly (dd7c7bd 2015-03-04) (built 2015-03-04)

I tried to fix it by adding use std::io::ReadExt, but it is not the only error...

(I hope I didn't do anything wrong...)

Example for router

Can you please show example for iron/router (not Chain)? When I use Router, I receive "no body".

Upgrade to serde 0.9

Serde 0.9 is currently usable on Rust beta (1.15) without any external codegen or feature gates, and 1.15 releases on Feb 2.

the trait `plugin::Plugin<iron::Request<'_, '_>>` is not implemented for `bodyparser::Raw`

I tried to use the example as a reference to get my own code working, but it fails with:

error[E0277]: the trait bound `bodyparser::Raw: plugin::Plugin<iron::Request<'_, '_>>` is not satisfied
  --> src/main.rs:27:24
   |
27 |         let body = req.get::<bodyparser::Raw>();
   |                        ^^^ the trait `plugin::Plugin<iron::Request<'_, '_>>` is not implemented for `bodyparser::Raw`
   |
   = help: the following implementations were found:
             <bodyparser::Raw as plugin::Plugin<iron::request::Request<'a, 'b>>>

The code in question:

    let (tx, rx) = mpsc::channel();
    let sender = Mutex::new(tx);
    let chain = Chain::new(move |req: &mut Request| -> IronResult<Response> {
        println!("received request");

        let body = req.get::<bodyparser::Raw>();
        match body {
            Ok(Some(body)) => println!("Read body:\n{}", body),
            Ok(None) => println!("No body"),
            Err(err) => println!("Error: {:?}", err),
        }

        let tx = sender.lock().unwrap().clone(); //Or whatever
        tx.send("request");

        return Ok(Response::with((status::Ok, "Hello World")));
    });
    chain.link_before(Read::<bodyparser::MaxBodyLength>::one(MAX_BODY_LENGTH));

    thread::spawn(move || {
        for received in rx {
            println!("{}", received)
        }
    });

    match Iron::new(chain).http(env::var("BIND").unwrap()) {
        Ok(_) => println!("fine"),
        Err(error) => panic!("failed to bind HTTP listener: {:?}", error),
    }

changelog.md

Please consider to add CHANGELOG.md to note breaking changes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.