1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-06-07 14:20:42 +00:00

update to gotham 0.5 and start using rustfmt

This commit is contained in:
Dominic 2020-09-15 15:10:41 +02:00
parent 5317e50961
commit d55b0897e9
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
39 changed files with 1798 additions and 2095 deletions

View file

@ -1,13 +1,8 @@
use gotham::{
hyper::header::CONTENT_TYPE,
router::builder::*,
test::TestServer
};
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.";
const RESPONSE: &[u8] = b"This is the only valid response.";
#[derive(Resource)]
#[resource(create)]
@ -21,23 +16,24 @@ struct Foo {
}
#[create(FooResource)]
fn create(body : Foo) -> Raw<Vec<u8>> {
fn create(body: Foo) -> Raw<Vec<u8>> {
Raw::new(body.content, body.content_type)
}
#[test]
fn custom_request_body()
{
fn custom_request_body() {
let server = TestServer::new(build_simple_router(|router| {
router.resource::<FooResource>("foo");
})).unwrap();
let res = server.client()
}))
.unwrap();
let res = server
.client()
.post("http://localhost/foo", RESPONSE, TEXT_PLAIN)
.perform().unwrap();
.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();
let body: &[u8] = res.as_ref();
assert_eq!(body, RESPONSE);
}