Skip to content

Commit ebb4b9f

Browse files
authored
Merge pull request #7 from jtgeibel/new-body
Add support for changes to `conduit::Body`
2 parents 6d4af12 + ec98454 commit ebb4b9f

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "conduit-conditional-get"
4-
version = "0.9.0-alpha.1"
4+
version = "0.9.0-alpha.2"
55
authors = ["[email protected]",
66
"Alex Crichton <[email protected]>"]
77
license = "MIT"
@@ -11,9 +11,9 @@ the response is fresh.
1111
"""
1212

1313
[dependencies]
14-
conduit = "0.9.0-alpha.1"
15-
conduit-middleware = "0.9.0-alpha.1"
14+
conduit = "0.9.0-alpha.2"
15+
conduit-middleware = "0.9.0-alpha.2"
1616
time = "0.1.0"
1717

1818
[dev-dependencies]
19-
conduit-test = "0.9.0-alpha.1"
19+
conduit-test = "0.9.0-alpha.2"

src/lib.rs

+11-25
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ extern crate time;
88
use conduit::{header, Body, HeaderMap, Method, RequestExt, Response, StatusCode};
99
use conduit_middleware::{AfterResult, Middleware};
1010
use std::borrow::Cow;
11-
use std::io;
1211
use time::{ParseError, Tm};
1312

1413
#[allow(missing_copy_implementations)]
@@ -25,7 +24,7 @@ impl Middleware for ConditionalGet {
2524
parts.status = StatusCode::NOT_MODIFIED;
2625
parts.headers.remove(header::CONTENT_TYPE);
2726
parts.headers.remove(header::CONTENT_LENGTH);
28-
return Ok(Response::from_parts(parts, Box::new(io::empty())));
27+
return Ok(Response::from_parts(parts, Body::empty()));
2928
}
3029
}
3130
_ => (),
@@ -112,11 +111,12 @@ fn parse_asctime(string: &str) -> Result<Tm, ParseError> {
112111

113112
#[cfg(test)]
114113
mod tests {
115-
extern crate conduit_test as test;
114+
extern crate conduit_test;
116115

116+
use self::conduit_test::{MockRequest, ResponseExt};
117117
use conduit::{
118-
box_error, header, static_to_body, Handler, HandlerResult, HeaderMap, Method, RequestExt,
119-
Response, StatusCode,
118+
box_error, header, Body, Handler, HandlerResult, HeaderMap, Method, RequestExt, Response,
119+
StatusCode,
120120
};
121121
use conduit_middleware::MiddlewareBuilder;
122122
use time;
@@ -141,7 +141,7 @@ mod tests {
141141

142142
macro_rules! request {
143143
($($header:expr => $value:expr),+) => ({
144-
let mut req = test::MockRequest::new(Method::GET, "/");
144+
let mut req = MockRequest::new(Method::GET, "/");
145145
$(req.header($header, &$value.to_string());)+
146146
req
147147
})
@@ -239,33 +239,19 @@ mod tests {
239239
}
240240

241241
fn expect_304(response: HandlerResult) {
242-
let mut response = response.ok().expect("No response");
243-
let mut body = Vec::new();
244-
response
245-
.body_mut()
246-
.write_body(&mut body)
247-
.ok()
248-
.expect("No body");
249-
242+
let response = response.expect("No response");
250243
assert_eq!(response.status(), StatusCode::NOT_MODIFIED);
251-
assert_eq!(body, b"");
244+
assert_eq!(response.into_cow(), "".as_bytes());
252245
}
253246

254247
fn expect_200(response: HandlerResult) {
255248
expect(StatusCode::OK, response);
256249
}
257250

258251
fn expect(status: StatusCode, response: HandlerResult) {
259-
let mut response = response.ok().expect("No response");
260-
let mut body = Vec::new();
261-
response
262-
.body_mut()
263-
.write_body(&mut body)
264-
.ok()
265-
.expect("No body");
266-
252+
let response = response.expect("No response");
267253
assert_eq!(response.status(), status);
268-
assert_eq!(body, b"hello");
254+
assert_eq!(response.into_cow(), "hello".as_bytes());
269255
}
270256

271257
struct SimpleHandler {
@@ -289,7 +275,7 @@ mod tests {
289275
let mut builder = Response::builder().status(self.status);
290276
builder.headers_mut().unwrap().extend(self.headers.clone());
291277
builder
292-
.body(static_to_body(self.body.as_bytes()))
278+
.body(Body::from_static(self.body.as_bytes()))
293279
.map_err(box_error)
294280
}
295281
}

0 commit comments

Comments
 (0)