[−][src]Function actix_web::test::read_body
pub fn read_body<B>(res: ServiceResponse<B>) -> Bytes where
B: MessageBody,
Helper function that returns a response body of a ServiceResponse. This function blocks the current thread until futures complete.
use actix_web::{test, web, App, HttpResponse, http::header}; use bytes::Bytes; #[test] fn test_index() { let mut app = test::init_service( App::new().service( web::resource("/index.html") .route(web::post().to( || HttpResponse::Ok().body("welcome!"))))); let req = test::TestRequest::post() .uri("/index.html") .header(header::CONTENT_TYPE, "application/json") .to_request(); let resp = test::call_service(&mut app, req); let result = test::read_body(resp); assert_eq!(result, Bytes::from_static(b"welcome!")); }