mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-01 00:44:26 +02:00
remove internal usage of Body
This commit is contained in:
@ -4,7 +4,7 @@ use std::future::Future;
|
||||
use std::marker::PhantomData;
|
||||
use std::rc::Rc;
|
||||
|
||||
use actix_http::body::{Body, MessageBody};
|
||||
use actix_http::body::{AnyBody, MessageBody};
|
||||
use actix_http::{Extensions, Request};
|
||||
use actix_service::boxed::{self, BoxServiceFactory};
|
||||
use actix_service::{
|
||||
@ -39,7 +39,7 @@ pub struct App<T, B> {
|
||||
_phantom: PhantomData<B>,
|
||||
}
|
||||
|
||||
impl App<AppEntry, Body> {
|
||||
impl App<AppEntry, AnyBody> {
|
||||
/// Create application builder. Application can be configured with a builder-like pattern.
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> Self {
|
||||
|
@ -14,6 +14,7 @@ pub use crate::types::form::UrlEncoded;
|
||||
pub use crate::types::json::JsonBody;
|
||||
pub use crate::types::readlines::Readlines;
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub use actix_http::body::{AnyBody, Body, BodySize, MessageBody, SizedStream};
|
||||
|
||||
#[cfg(feature = "__compress")]
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::{cell::RefCell, fmt, io::Write as _};
|
||||
|
||||
use actix_http::{body::Body, header, StatusCode};
|
||||
use actix_http::{body::AnyBody, header, StatusCode};
|
||||
use bytes::{BufMut as _, BytesMut};
|
||||
|
||||
use crate::{Error, HttpRequest, HttpResponse, Responder, ResponseError};
|
||||
@ -88,7 +88,7 @@ where
|
||||
header::CONTENT_TYPE,
|
||||
header::HeaderValue::from_static("text/plain; charset=utf-8"),
|
||||
);
|
||||
res.set_body(Body::from(buf.into_inner()))
|
||||
res.set_body(AnyBody::from(buf.into_inner()))
|
||||
}
|
||||
|
||||
InternalErrorType::Response(ref resp) => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use actix_http::{
|
||||
body::Body,
|
||||
body::AnyBody,
|
||||
http::{header::IntoHeaderPair, Error as HttpError, HeaderMap, StatusCode},
|
||||
};
|
||||
use bytes::{Bytes, BytesMut};
|
||||
@ -65,7 +65,7 @@ impl Responder for HttpResponse {
|
||||
}
|
||||
}
|
||||
|
||||
impl Responder for actix_http::Response<Body> {
|
||||
impl Responder for actix_http::Response<AnyBody> {
|
||||
#[inline]
|
||||
fn respond_to(self, _: &HttpRequest) -> HttpResponse {
|
||||
HttpResponse::from(self)
|
||||
@ -254,7 +254,7 @@ pub(crate) mod tests {
|
||||
let resp = srv.call(req).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
match resp.response().body() {
|
||||
Body::Bytes(ref b) => {
|
||||
AnyBody::Bytes(ref b) => {
|
||||
let bytes = b.clone();
|
||||
assert_eq!(bytes, Bytes::from_static(b"some"));
|
||||
}
|
||||
@ -267,14 +267,14 @@ pub(crate) mod tests {
|
||||
fn body(&self) -> &AnyBody;
|
||||
}
|
||||
|
||||
impl BodyTest for Body {
|
||||
impl BodyTest for AnyBody {
|
||||
fn bin_ref(&self) -> &[u8] {
|
||||
match self {
|
||||
AnyBody::Bytes(ref bin) => bin,
|
||||
_ => unreachable!("bug in test impl"),
|
||||
}
|
||||
}
|
||||
fn body(&self) -> &Body {
|
||||
fn body(&self) -> &AnyBody {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
@ -436,7 +436,7 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
dev::Body,
|
||||
dev::AnyBody,
|
||||
http::{
|
||||
header::{self, HeaderValue, CONTENT_TYPE},
|
||||
StatusCode,
|
||||
@ -475,7 +475,7 @@ mod tests {
|
||||
fn test_content_type() {
|
||||
let resp = HttpResponseBuilder::new(StatusCode::OK)
|
||||
.content_type("text/plain")
|
||||
.body(Body::empty());
|
||||
.body(AnyBody::empty());
|
||||
assert_eq!(resp.headers().get(CONTENT_TYPE).unwrap(), "text/plain")
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ use std::{
|
||||
};
|
||||
|
||||
use actix_http::{
|
||||
body::{AnyBody, Body, MessageBody},
|
||||
body::{AnyBody, MessageBody},
|
||||
http::{header::HeaderMap, StatusCode},
|
||||
Extensions, Response, ResponseHead,
|
||||
};
|
||||
@ -273,14 +273,14 @@ impl<B> From<HttpResponse<B>> for Response<B> {
|
||||
}
|
||||
}
|
||||
|
||||
// Future is only implemented for Body payload type because it's the most useful for making simple
|
||||
// handlers without async blocks. Making it generic over all MessageBody types requires a future
|
||||
// impl on Response which would cause it's body field to be, undesirably, Option<B>.
|
||||
// Future is only implemented for AnyBody payload type because it's the most useful for making
|
||||
// simple handlers without async blocks. Making it generic over all MessageBody types requires a
|
||||
// future impl on Response which would cause it's body field to be, undesirably, Option<B>.
|
||||
//
|
||||
// This impl is not particularly efficient due to the Response construction and should probably
|
||||
// not be invoked if performance is important. Prefer an async fn/block in such cases.
|
||||
impl Future for HttpResponse<Body> {
|
||||
type Output = Result<Response<Body>, Error>;
|
||||
impl Future for HttpResponse<AnyBody> {
|
||||
type Output = Result<Response<AnyBody>, Error>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
if let Some(err) = self.error.take() {
|
||||
|
@ -580,7 +580,7 @@ mod tests {
|
||||
use bytes::Bytes;
|
||||
|
||||
use crate::{
|
||||
dev::Body,
|
||||
dev::AnyBody,
|
||||
guard,
|
||||
http::{header, HeaderValue, Method, StatusCode},
|
||||
middleware::DefaultHeaders,
|
||||
@ -752,7 +752,7 @@ mod tests {
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
|
||||
match resp.response().body() {
|
||||
Body::Bytes(ref b) => {
|
||||
AnyBody::Bytes(ref b) => {
|
||||
let bytes = b.clone();
|
||||
assert_eq!(bytes, Bytes::from_static(b"project: project1"));
|
||||
}
|
||||
@ -853,7 +853,7 @@ mod tests {
|
||||
assert_eq!(resp.status(), StatusCode::CREATED);
|
||||
|
||||
match resp.response().body() {
|
||||
Body::Bytes(ref b) => {
|
||||
AnyBody::Bytes(ref b) => {
|
||||
let bytes = b.clone();
|
||||
assert_eq!(bytes, Bytes::from_static(b"project: project_1"));
|
||||
}
|
||||
@ -881,7 +881,7 @@ mod tests {
|
||||
assert_eq!(resp.status(), StatusCode::CREATED);
|
||||
|
||||
match resp.response().body() {
|
||||
Body::Bytes(ref b) => {
|
||||
AnyBody::Bytes(ref b) => {
|
||||
let bytes = b.clone();
|
||||
assert_eq!(bytes, Bytes::from_static(b"project: test - 1"));
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ use crate::{
|
||||
app_service::AppInitServiceState,
|
||||
config::AppConfig,
|
||||
data::Data,
|
||||
dev::{Body, MessageBody, Payload},
|
||||
dev::{AnyBody, MessageBody, Payload},
|
||||
http::header::ContentType,
|
||||
rmap::ResourceMap,
|
||||
service::{ServiceRequest, ServiceResponse},
|
||||
@ -32,14 +32,14 @@ use crate::{
|
||||
|
||||
/// Create service that always responds with `HttpResponse::Ok()` and no body.
|
||||
pub fn ok_service(
|
||||
) -> impl Service<ServiceRequest, Response = ServiceResponse<Body>, Error = Error> {
|
||||
) -> impl Service<ServiceRequest, Response = ServiceResponse<AnyBody>, Error = Error> {
|
||||
default_service(StatusCode::OK)
|
||||
}
|
||||
|
||||
/// Create service that always responds with given status code and no body.
|
||||
pub fn default_service(
|
||||
status_code: StatusCode,
|
||||
) -> impl Service<ServiceRequest, Response = ServiceResponse<Body>, Error = Error> {
|
||||
) -> impl Service<ServiceRequest, Response = ServiceResponse<AnyBody>, Error = Error> {
|
||||
(move |req: ServiceRequest| {
|
||||
ok(req.into_response(HttpResponseBuilder::new(status_code).finish()))
|
||||
})
|
||||
|
Reference in New Issue
Block a user