From e6787cd62165a075c7f16a32f8bbacc398f52d13 Mon Sep 17 00:00:00 2001
From: Rob Ede <robjtede@icloud.com>
Date: Mon, 28 Feb 2022 00:28:57 +0000
Subject: [PATCH] Update actix-web depedency to 4.0.0 (#331)

---
 CHANGELOG.md       |  2 ++
 doctest/Cargo.toml |  2 +-
 maud/Cargo.toml    |  4 ++--
 maud/src/lib.rs    | 16 ++++++++--------
 4 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 596d9e9..6c9a0eb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@
   [#320](https://github.com/lambda-fairy/maud/pull/320)
 - Update to axum-core 0.1. This requires axum 0.4
   [#325](https://github.com/lambda-fairy/maud/pull/325)
+- Update to `actix-web` 4.0.
+  [#331](https://github.com/lambda-fairy/maud/pull/331)
 
 ## [0.23.0] - 2021-11-10
 
diff --git a/doctest/Cargo.toml b/doctest/Cargo.toml
index fb8d674..ad02936 100644
--- a/doctest/Cargo.toml
+++ b/doctest/Cargo.toml
@@ -5,7 +5,7 @@ authors = ["Chris Wong <lambda.fairy@gmail.com>"]
 edition = "2018"
 
 [dependencies]
-actix-web = "3"
+actix-web = { version = "4.0.0-rc.2", default-features = false, features = ["macros"] }
 ammonia = "3"
 maud = { path = "../maud", features = ["actix-web", "rocket", "tide", "axum"] }
 pulldown-cmark = "0.8"
diff --git a/maud/Cargo.toml b/maud/Cargo.toml
index 45c9ef9..939801a 100644
--- a/maud/Cargo.toml
+++ b/maud/Cargo.toml
@@ -13,17 +13,17 @@ edition = "2021"
 
 [features]
 default = []
-axum = ["axum-core", "http"]
 
 # Web framework integrations
 actix-web = ["actix-web-dep", "futures-util"]
+axum = ["axum-core", "http"]
 
 [dependencies]
 maud_macros = { version = "0.23.0", path = "../maud_macros" }
 itoa = { version = "0.4.8", default-features = false, features = ["i128"] }
 rocket = { version = ">= 0.3, < 0.5", optional = true }
 futures-util = { version = "0.3.0", optional = true, default-features = false }
-actix-web-dep = { package = "actix-web", version = ">= 2, < 4", optional = true, default-features = false }
+actix-web-dep = { package = "actix-web", version = "4", optional = true, default-features = false }
 tide = { version = "0.16.0", optional = true, default-features = false }
 axum-core = { version = "0.1", optional = true }
 http = { version = "0.2", optional = true }
diff --git a/maud/src/lib.rs b/maud/src/lib.rs
index 9450f2c..73ac24f 100644
--- a/maud/src/lib.rs
+++ b/maud/src/lib.rs
@@ -262,17 +262,17 @@ mod rocket_support {
 #[cfg(feature = "actix-web")]
 mod actix_support {
     use crate::PreEscaped;
-    use actix_web_dep::{Error, HttpRequest, HttpResponse, Responder};
+    use actix_web_dep::{http::header, HttpRequest, HttpResponse, Responder};
     use alloc::string::String;
-    use futures_util::future::{ok, Ready};
 
     impl Responder for PreEscaped<String> {
-        type Error = Error;
-        type Future = Ready<Result<HttpResponse, Self::Error>>;
-        fn respond_to(self, _req: &HttpRequest) -> Self::Future {
-            ok(HttpResponse::Ok()
-                .content_type("text/html; charset=utf-8")
-                .body(self.0))
+        type Body = String;
+
+        fn respond_to(self, _req: &HttpRequest) -> HttpResponse<Self::Body> {
+            HttpResponse::Ok()
+                .content_type(header::ContentType::html())
+                .message_body(self.0)
+                .unwrap()
         }
     }
 }