Skip to content

Commit

Permalink
remove default logger middleware. (#928)
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeshadow authored Feb 8, 2024
1 parent 6e59173 commit 64e1748
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
1 change: 1 addition & 0 deletions web/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

## Remove
- remove `xitca_web::error::{BadRequest, Internal}` types. `xitca_web::error::ErrorStatus` replace their roles where `ErrorStatus::bad_request` and `ErrorStatus::internal` would generate identical error information as `BadRequest` and `Internal` types. this change would simplify runtime error type casting a bit with two less possible error types.
- remove default logger middleware from `xitca_web::HttpServer::{bind_xxx, listen_xxx}` APIs.

## Change
- change `xitca_web::middleware::eraser::TypeEraser::error`'s trait bound. `From` trait is used for conversion between generic error type and `xitca_web::error::Error`. With this change `Error` does not double boxing itself therefore removing the need of nested type casting when handling typed error.
Expand Down
6 changes: 5 additions & 1 deletion web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ file = ["http-file", "nightly"]
# rate-limit middleware
rate-limit = ["http-rate"]

# nightly rust required feature
# nightly rust required feature.
#
# IMPORTANT note when utilizing nightly feature:
# nightly feature is unstable and would not take part in semver practice. all breaking change
# origin from it would be seen as non breaking from stable release point of view.
nightly = []

# macro code generation
Expand Down
2 changes: 1 addition & 1 deletion web/src/handler/types/redirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<'r, C, B> Responder<WebContext<'r, C, B>> for Redirect {
}

fn map(self, res: Self::Response) -> Result<Self::Response, Self::Error> {
let location = self.location.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let location = self.location?;
let map = (self.status, (LOCATION, location));
Responder::<WebContext<'r, C, B>>::map(map, res)
}
Expand Down
25 changes: 5 additions & 20 deletions web/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use futures_core::stream::Stream;
use xitca_http::{
body::RequestBody,
config::{HttpServiceConfig, DEFAULT_HEADER_LIMIT, DEFAULT_READ_BUF_LIMIT, DEFAULT_WRITE_BUF_LIMIT},
util::middleware::Logger,
HttpServiceBuilder,
};
use xitca_server::{Builder, ServerFuture};
Expand Down Expand Up @@ -180,11 +179,7 @@ where
BE: fmt::Debug + 'static,
{
let config = self.config;
let service = self
.service
.clone()
.enclosed(HttpServiceBuilder::with_config(config))
.enclosed(Logger::new());
let service = self.service.clone().enclosed(HttpServiceBuilder::with_config(config));
self.builder = self.builder.bind("xitca-web", addr, service)?;
Ok(self)
}
Expand All @@ -200,11 +195,7 @@ where
BE: fmt::Debug + 'static,
{
let config = self.config;
let service = self
.service
.clone()
.enclosed(HttpServiceBuilder::with_config(config))
.enclosed(Logger::new());
let service = self.service.clone().enclosed(HttpServiceBuilder::with_config(config));
self.builder = self.builder.listen("xitca-web", listener, service);
Ok(self)
}
Expand Down Expand Up @@ -258,8 +249,7 @@ where
let service = self
.service
.clone()
.enclosed(HttpServiceBuilder::with_config(config).openssl(acceptor))
.enclosed(Logger::new());
.enclosed(HttpServiceBuilder::with_config(config).openssl(acceptor));

self.builder = self.builder.bind("xitca-web-openssl", addr, service)?;

Expand Down Expand Up @@ -295,8 +285,7 @@ where
let service = self
.service
.clone()
.enclosed(HttpServiceBuilder::with_config(service_config).rustls(config))
.enclosed(Logger::new());
.enclosed(HttpServiceBuilder::with_config(service_config).rustls(config));

self.builder = self.builder.bind("xitca-web-rustls", addr, service)?;

Expand All @@ -315,11 +304,7 @@ where
BE: fmt::Debug + 'static,
{
let config = self.config;
let service = self
.service
.clone()
.enclosed(HttpServiceBuilder::with_config(config))
.enclosed(Logger::new());
let service = self.service.clone().enclosed(HttpServiceBuilder::with_config(config));
self.builder = self.builder.bind_unix("xitca-web", path, service)?;
Ok(self)
}
Expand Down

0 comments on commit 64e1748

Please sign in to comment.