Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-export ServiceFactory #2325

Merged
merged 7 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changes

## Unreleased - 2021-xx-xx
### Added
* Re-export actix-service `ServiceFactory` in `dev` module. [#2325]

[#2325]: https://github.com/actix/actix-web/pull/2325


## 4.0.0-beta.8 - 2021-06-26
Expand Down
2 changes: 1 addition & 1 deletion actix-http/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
HttpMessage,
};

/// Request
/// An HTTP request.
pub struct Request<P = PayloadStream> {
pub(crate) payload: Payload<P>,
pub(crate) head: Message<RequestHead>,
Expand Down
25 changes: 9 additions & 16 deletions src/dev.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
//! Lower level `actix-web` types.
//! Lower-level types and re-exports.
//!
//! Most users will not have to interact with the types in this module,
//! but it is useful as a glob import for those writing middleware, developing libraries,
//! or interacting with the service API directly:
//!
//! ```
//! # #![allow(unused_imports)]
//! use actix_web::dev::*;
//! ```
//! Most users will not have to interact with the types in this module, but it is useful for those
//! writing extractors, middleware and libraries, or interacting with the service API directly.

pub use crate::config::{AppConfig, AppService};
#[doc(hidden)]
Expand All @@ -24,26 +18,25 @@ pub use actix_http::body::{AnyBody, Body, BodySize, MessageBody, ResponseBody, S

#[cfg(feature = "__compress")]
pub use actix_http::encoding::Decoder as Decompress;
pub use actix_http::ResponseBuilder as BaseHttpResponseBuilder;
pub use actix_http::{Extensions, Payload, PayloadStream, RequestHead, ResponseHead};
pub use actix_router::{Path, ResourceDef, ResourcePath, Url};
pub use actix_server::Server;
pub use actix_service::{
always_ready, fn_factory, fn_service, forward_ready, Service, Transform,
always_ready, fn_factory, fn_service, forward_ready, Service, ServiceFactory, Transform,
};

pub(crate) fn insert_slash(mut patterns: Vec<String>) -> Vec<String> {
use crate::http::header::ContentEncoding;
use actix_http::{Response, ResponseBuilder};

pub(crate) fn insert_leading_slash(mut patterns: Vec<String>) -> Vec<String> {
for path in &mut patterns {
if !path.is_empty() && !path.starts_with('/') {
path.insert(0, '/');
};
}

patterns
}

use crate::http::header::ContentEncoding;
use actix_http::{Response, ResponseBuilder};

struct Enc(ContentEncoding);

/// Helper trait that allows to set specific encoding for response.
Expand Down
4 changes: 2 additions & 2 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ use crate::{
#[cfg(feature = "cookies")]
struct Cookies(Vec<Cookie<'static>>);

/// An incoming request.
#[derive(Clone)]
/// An HTTP Request
pub struct HttpRequest {
/// # Panics
/// # Invariant
/// `Rc<HttpRequestInner>` is used exclusively and NO `Weak<HttpRequestInner>`
/// is allowed anywhere in the code. Weak pointer is purposely ignored when
/// doing `Rc`'s ref counter check. Expect panics if this invariant is violated.
Expand Down
4 changes: 2 additions & 2 deletions src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use futures_util::future::join_all;

use crate::{
data::Data,
dev::{insert_slash, AppService, HttpServiceFactory, ResourceDef},
dev::{insert_leading_slash, AppService, HttpServiceFactory, ResourceDef},
guard::Guard,
handler::Handler,
responder::Responder,
Expand Down Expand Up @@ -391,7 +391,7 @@ where
};

let mut rdef = if config.is_root() || !self.rdef.is_empty() {
ResourceDef::new(insert_slash(self.rdef.clone()))
ResourceDef::new(insert_leading_slash(self.rdef.clone()))
} else {
ResourceDef::new(self.rdef.clone())
};
Expand Down
16 changes: 8 additions & 8 deletions src/response/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,14 @@ use {

use crate::{error::Error, HttpResponseBuilder};

/// An HTTP Response
/// An outgoing response.
pub struct HttpResponse<B = AnyBody> {
res: Response<B>,
pub(crate) error: Option<Error>,
}

impl HttpResponse<AnyBody> {
/// Create HTTP response builder with specific status.
#[inline]
pub fn build(status: StatusCode) -> HttpResponseBuilder {
HttpResponseBuilder::new(status)
}

/// Create a response.
/// Constructs a response.
#[inline]
pub fn new(status: StatusCode) -> Self {
Self {
Expand All @@ -46,6 +40,12 @@ impl HttpResponse<AnyBody> {
}
}

/// Constructs a response builder with specific HTTP status.
#[inline]
pub fn build(status: StatusCode) -> HttpResponseBuilder {
HttpResponseBuilder::new(status)
}

/// Create an error response.
#[inline]
pub fn from_error(error: impl Into<Error>) -> Self {
Expand Down
9 changes: 5 additions & 4 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use cookie::{Cookie, ParseError as CookieParseError};

use crate::{
config::{AppConfig, AppService},
dev::insert_slash,
dev::insert_leading_slash,
guard::Guard,
info::ConnectionInfo,
rmap::ResourceMap,
Expand Down Expand Up @@ -59,9 +59,9 @@ where
}
}

/// An service http request
/// A service level request wrapper.
///
/// ServiceRequest allows mutable access to request's internal structures
/// Allows mutable access to request's internal structures.
pub struct ServiceRequest {
req: HttpRequest,
payload: Payload,
Expand Down Expand Up @@ -325,6 +325,7 @@ impl fmt::Debug for ServiceRequest {
}
}

/// A service level response wrapper.
pub struct ServiceResponse<B = AnyBody> {
request: HttpRequest,
response: HttpResponse<B>,
Expand Down Expand Up @@ -550,7 +551,7 @@ where
};

let mut rdef = if config.is_root() || !self.rdef.is_empty() {
ResourceDef::new(insert_slash(self.rdef))
ResourceDef::new(insert_leading_slash(self.rdef))
} else {
ResourceDef::new(self.rdef)
};
Expand Down