@@ -8,7 +8,6 @@ extern crate time;
8
8
use conduit:: { header, Body , HeaderMap , Method , RequestExt , Response , StatusCode } ;
9
9
use conduit_middleware:: { AfterResult , Middleware } ;
10
10
use std:: borrow:: Cow ;
11
- use std:: io;
12
11
use time:: { ParseError , Tm } ;
13
12
14
13
#[ allow( missing_copy_implementations) ]
@@ -25,7 +24,7 @@ impl Middleware for ConditionalGet {
25
24
parts. status = StatusCode :: NOT_MODIFIED ;
26
25
parts. headers . remove ( header:: CONTENT_TYPE ) ;
27
26
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 ( ) ) ) ;
29
28
}
30
29
}
31
30
_ => ( ) ,
@@ -112,11 +111,12 @@ fn parse_asctime(string: &str) -> Result<Tm, ParseError> {
112
111
113
112
#[ cfg( test) ]
114
113
mod tests {
115
- extern crate conduit_test as test ;
114
+ extern crate conduit_test;
116
115
116
+ use self :: conduit_test:: { MockRequest , ResponseExt } ;
117
117
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 ,
120
120
} ;
121
121
use conduit_middleware:: MiddlewareBuilder ;
122
122
use time;
@@ -141,7 +141,7 @@ mod tests {
141
141
142
142
macro_rules! request {
143
143
( $( $header: expr => $value: expr) ,+) => ( {
144
- let mut req = test :: MockRequest :: new( Method :: GET , "/" ) ;
144
+ let mut req = MockRequest :: new( Method :: GET , "/" ) ;
145
145
$( req. header( $header, & $value. to_string( ) ) ; ) +
146
146
req
147
147
} )
@@ -239,33 +239,19 @@ mod tests {
239
239
}
240
240
241
241
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" ) ;
250
243
assert_eq ! ( response. status( ) , StatusCode :: NOT_MODIFIED ) ;
251
- assert_eq ! ( body , b"" ) ;
244
+ assert_eq ! ( response . into_cow ( ) , "" . as_bytes ( ) ) ;
252
245
}
253
246
254
247
fn expect_200 ( response : HandlerResult ) {
255
248
expect ( StatusCode :: OK , response) ;
256
249
}
257
250
258
251
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" ) ;
267
253
assert_eq ! ( response. status( ) , status) ;
268
- assert_eq ! ( body , b "hello") ;
254
+ assert_eq ! ( response . into_cow ( ) , "hello" . as_bytes ( ) ) ;
269
255
}
270
256
271
257
struct SimpleHandler {
@@ -289,7 +275,7 @@ mod tests {
289
275
let mut builder = Response :: builder ( ) . status ( self . status ) ;
290
276
builder. headers_mut ( ) . unwrap ( ) . extend ( self . headers . clone ( ) ) ;
291
277
builder
292
- . body ( static_to_body ( self . body . as_bytes ( ) ) )
278
+ . body ( Body :: from_static ( self . body . as_bytes ( ) ) )
293
279
. map_err ( box_error)
294
280
}
295
281
}
0 commit comments