1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-28 15:57:47 +02:00

Update Middleware trait to use &mut self

This commit is contained in:
Josh Leeb-du Toit
2018-06-02 13:37:29 +10:00
parent 8d73c30dae
commit 9c9eb62031
15 changed files with 111 additions and 90 deletions

View File

@@ -355,7 +355,7 @@ impl Cors {
}
impl<S> Middleware<S> for Cors {
fn start(&self, req: &mut HttpRequest<S>) -> Result<Started> {
fn start(&mut self, req: &mut HttpRequest<S>) -> Result<Started> {
if self.inner.preflight && Method::OPTIONS == *req.method() {
self.validate_origin(req)?;
self.validate_allowed_method(req)?;
@@ -430,7 +430,7 @@ impl<S> Middleware<S> for Cors {
}
fn response(
&self, req: &mut HttpRequest<S>, mut resp: HttpResponse,
&mut self, req: &mut HttpRequest<S>, mut resp: HttpResponse,
) -> Result<Response> {
match self.inner.origins {
AllOrSome::All => {
@@ -940,7 +940,7 @@ mod tests {
#[test]
fn validate_origin_allows_all_origins() {
let cors = Cors::default();
let mut cors = Cors::default();
let mut req =
TestRequest::with_header("Origin", "https://www.example.com").finish();
@@ -1009,7 +1009,7 @@ mod tests {
#[test]
#[should_panic(expected = "MissingOrigin")]
fn test_validate_missing_origin() {
let cors = Cors::build()
let mut cors = Cors::build()
.allowed_origin("https://www.example.com")
.finish();
@@ -1020,7 +1020,7 @@ mod tests {
#[test]
#[should_panic(expected = "OriginNotAllowed")]
fn test_validate_not_allowed_origin() {
let cors = Cors::build()
let mut cors = Cors::build()
.allowed_origin("https://www.example.com")
.finish();
@@ -1032,7 +1032,7 @@ mod tests {
#[test]
fn test_validate_origin() {
let cors = Cors::build()
let mut cors = Cors::build()
.allowed_origin("https://www.example.com")
.finish();
@@ -1045,7 +1045,7 @@ mod tests {
#[test]
fn test_no_origin_response() {
let cors = Cors::build().finish();
let mut cors = Cors::build().finish();
let mut req = TestRequest::default().method(Method::GET).finish();
let resp: HttpResponse = HttpResponse::Ok().into();
@@ -1071,7 +1071,7 @@ mod tests {
#[test]
fn test_response() {
let cors = Cors::build()
let mut cors = Cors::build()
.send_wildcard()
.disable_preflight()
.max_age(3600)
@@ -1106,7 +1106,7 @@ mod tests {
resp.headers().get(header::VARY).unwrap().as_bytes()
);
let cors = Cors::build()
let mut cors = Cors::build()
.disable_vary_header()
.allowed_origin("https://www.example.com")
.finish();