mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-04-20 06:54:46 +00:00
merge workspace and main crate
This commit is contained in:
parent
52679ad29d
commit
5587ded60d
45 changed files with 58 additions and 67 deletions
49
tests/custom_request_body.rs
Normal file
49
tests/custom_request_body.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
mod custom_request_body
|
||||
{
|
||||
|
||||
|
||||
use gotham::{
|
||||
hyper::header::CONTENT_TYPE,
|
||||
router::builder::*,
|
||||
test::TestServer
|
||||
};
|
||||
use gotham_restful::*;
|
||||
use mime::TEXT_PLAIN;
|
||||
|
||||
const RESPONSE : &[u8] = b"This is the only valid response.";
|
||||
|
||||
#[derive(Resource)]
|
||||
#[resource(create)]
|
||||
struct FooResource;
|
||||
|
||||
#[derive(FromBody, RequestBody)]
|
||||
#[supported_types(TEXT_PLAIN)]
|
||||
struct Foo {
|
||||
content: Vec<u8>,
|
||||
content_type: Mime
|
||||
}
|
||||
|
||||
#[create(FooResource)]
|
||||
fn create(body : Foo) -> Raw<Vec<u8>> {
|
||||
Raw::new(body.content, body.content_type)
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test()
|
||||
{
|
||||
let server = TestServer::new(build_simple_router(|router| {
|
||||
router.resource::<FooResource>("foo");
|
||||
})).unwrap();
|
||||
|
||||
let res = server.client()
|
||||
.post("http://localhost/foo", RESPONSE, TEXT_PLAIN)
|
||||
.perform().unwrap();
|
||||
assert_eq!(res.headers().get(CONTENT_TYPE).unwrap().to_str().unwrap(), "text/plain");
|
||||
let res = res.read_body().unwrap();
|
||||
let body : &[u8] = res.as_ref();
|
||||
assert_eq!(body, RESPONSE);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue