Merge pull request #52 from storytold/bt-upgrade-actix-4

upgrade to actix 4
This commit is contained in:
Brandon Thomas authored and GitHub committed 2023-07-19 02:53:40 -04:00
commit cf27fca799
105 files changed
+238 -872

No files matched your search

Generated
+79 -200
View File
@@ -119,23 +119,6 @@ dependencies = [
"tokio-util 0.3.1",
]
[[package]]
name = "actix-codec"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13895df506faee81e423febbae3a33b27fca71831b96bb3d60adf16ebcfea952"
dependencies = [
"bitflags",
"bytes 1.3.0",
"futures-core",
"futures-sink",
"log",
"memchr",
"pin-project-lite 0.2.9",
"tokio 1.25.0",
"tokio-util 0.6.9",
]
[[package]]
name = "actix-codec"
version = "0.5.1"
@@ -188,12 +171,12 @@ dependencies = [
[[package]]
name = "actix-cors"
version = "0.6.0-beta.3"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa59d36d7ad063401d94ada05264a303791796ad5222d0954cc21f2e1052e99b"
checksum = "b340e9cfa5b08690aae90fb61beb44e9b06f44fe3d0f93781aaa58cfba86245e"
dependencies = [
"actix-service 2.0.1",
"actix-web 4.0.0-beta.10",
"actix-utils 3.0.0",
"actix-web 4.0.1",
"derive_more",
"futures-util",
"log",
@@ -203,14 +186,14 @@ dependencies = [
[[package]]
name = "actix-files"
version = "0.6.0-beta.8"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3754d4632de16dd68f6a5d379cf9d7200ec26020482e26aa16560a258e92f3"
checksum = "d832782fac6ca7369a70c9ee9a20554623c5e51c76e190ad151780ebea1cf689"
dependencies = [
"actix-http 3.3.0",
"actix-service 2.0.1",
"actix-utils 3.0.0",
"actix-web 4.0.0-beta.10",
"actix-web 4.0.1",
"askama_escape",
"bitflags",
"bytes 1.3.0",
@@ -221,6 +204,7 @@ dependencies = [
"mime",
"mime_guess",
"percent-encoding 2.2.0",
"pin-project-lite 0.2.9",
]
[[package]]
@@ -279,6 +263,7 @@ dependencies = [
"actix-service 2.0.1",
"actix-utils 3.0.0",
"ahash 0.7.6",
"base64 0.21.0",
"bitflags",
"brotli",
"bytes 1.3.0",
@@ -287,14 +272,18 @@ dependencies = [
"encoding_rs",
"flate2",
"futures-core",
"h2 0.3.15",
"http",
"httparse",
"httpdate 1.0.1",
"itoa 1.0.3",
"language-tags 0.3.2",
"local-channel",
"mime",
"percent-encoding 2.2.0",
"pin-project-lite 0.2.9",
"rand 0.8.5",
"sha1 0.10.4",
"smallvec 1.10.0",
"tokio 1.25.0",
"tokio-util 0.7.4",
@@ -329,7 +318,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee3878dadc5d0e2afa0439b4e1ef3b03fa2feb72c208d8c6f196ed6242979f6d"
dependencies = [
"actix-utils 3.0.0",
"actix-web 4.0.0-beta.10",
"actix-web 4.0.1",
"bytes 1.3.0",
"derive_more",
"futures-core",
@@ -356,16 +345,15 @@ dependencies = [
[[package]]
name = "actix-router"
version = "0.5.0-beta.2"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36b95ce0d76d1aa2f98b681702807475ade0f99bd4552546a6843a966d42ea3d"
checksum = "d66ff4d247d2b160861fa2866457e85706833527840e4133f8f49aa423a38799"
dependencies = [
"bytestring",
"firestorm",
"http",
"log",
"regex",
"serde",
"tracing",
]
[[package]]
@@ -416,18 +404,20 @@ dependencies = [
[[package]]
name = "actix-server"
version = "2.0.0-beta.6"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7367665785765b066ad16e1086d26a087f696bc7c42b6f93004ced6cfcf1eeca"
checksum = "0da34f8e659ea1b077bb4637948b815cd3768ad5a188fdcd74ff4d84240cd824"
dependencies = [
"actix-rt 2.7.0",
"actix-service 2.0.1",
"actix-utils 3.0.0",
"futures-core",
"log",
"mio 0.7.11",
"futures-util",
"mio 0.8.5",
"num_cpus",
"socket2 0.4.7",
"tokio 1.25.0",
"tracing",
]
[[package]]
@@ -563,35 +553,34 @@ dependencies = [
[[package]]
name = "actix-web"
version = "4.0.0-beta.10"
version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8a4b9d00991d8da308070a5cea7f1bbaa153a91c3fb5567937d99b9f46d601e"
checksum = "f4e5ebffd51d50df56a3ae0de0e59487340ca456f05dd0b90c0a7a6dd6a74d31"
dependencies = [
"actix-codec 0.4.1",
"actix-codec 0.5.1",
"actix-http 3.3.0",
"actix-macros 0.2.3",
"actix-router 0.5.0-beta.2",
"actix-router 0.5.1",
"actix-rt 2.7.0",
"actix-server 2.0.0-beta.6",
"actix-server 2.1.1",
"actix-service 2.0.1",
"actix-utils 3.0.0",
"actix-web-codegen 0.5.0-beta.5",
"actix-web-codegen 4.2.0",
"ahash 0.7.6",
"bytes 1.3.0",
"bytestring",
"cfg-if 1.0.0",
"cookie 0.15.1",
"cookie 0.16.2",
"derive_more",
"either",
"encoding_rs",
"futures-core",
"futures-util",
"itoa 0.4.7",
"itoa 1.0.3",
"language-tags 0.3.2",
"log",
"mime",
"once_cell",
"paste",
"pin-project 1.0.7",
"pin-project-lite 0.2.9",
"regex",
"serde",
"serde_json",
@@ -604,19 +593,20 @@ dependencies = [
[[package]]
name = "actix-web-actors"
version = "4.0.0-beta.7"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b43c8e03f1877bc010316de455ee479aa0de0ae0717d49041db5f38fa192de"
checksum = "bf6e9ccc371cfddbed7aa842256a4abc7a6dcac9f3fce392fe1d0f68cfd136b2"
dependencies = [
"actix",
"actix-codec 0.4.1",
"actix-codec 0.5.1",
"actix-http 3.3.0",
"actix-web 4.0.0-beta.10",
"actix-web 4.0.1",
"bytes 1.3.0",
"bytestring",
"futures-core",
"pin-project 1.0.7",
"pin-project-lite 0.2.9",
"tokio 1.25.0",
"tokio-util 0.7.4",
]
[[package]]
@@ -632,11 +622,11 @@ dependencies = [
[[package]]
name = "actix-web-codegen"
version = "0.5.0-beta.5"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfe80a8828fa88a0420dc8fdd4c16b8207326c917f17701881b063eadc2a8d3b"
checksum = "2262160a7ae29e3415554a3f1fc04c764b1540c116aa524683208078b7a75bc9"
dependencies = [
"actix-router 0.5.0-beta.2",
"actix-router 0.5.1",
"proc-macro2",
"quote",
"syn 1.0.107",
@@ -657,14 +647,14 @@ dependencies = [
name = "actix_helpers"
version = "0.0.1"
dependencies = [
"actix-cors 0.6.0-beta.3",
"actix-cors 0.6.4",
"actix-files",
"actix-http 3.3.0",
"actix-multipart",
"actix-rt 2.7.0",
"actix-service 2.0.1",
"actix-utils 3.0.0",
"actix-web 4.0.0-beta.10",
"actix-web 4.0.1",
"actix-web-actors",
"cidr-utils",
"errors",
@@ -736,14 +726,14 @@ dependencies = [
name = "aichatbot-sidecar"
version = "0.0.1"
dependencies = [
"actix-cors 0.6.0-beta.3",
"actix-cors 0.6.4",
"actix-files",
"actix-http 3.3.0",
"actix-multipart",
"actix-rt 2.7.0",
"actix-service 2.0.1",
"actix-utils 3.0.0",
"actix-web 4.0.0-beta.10",
"actix-web 4.0.1",
"actix-web-actors",
"actix_helpers",
"async-openai",
@@ -1165,9 +1155,9 @@ dependencies = [
name = "billing_component"
version = "0.0.1"
dependencies = [
"actix-cors 0.6.0-beta.3",
"actix-cors 0.6.4",
"actix-http 3.3.0",
"actix-web 4.0.0-beta.10",
"actix-web 4.0.1",
"anyhow",
"async-stripe",
"async-trait",
@@ -1649,9 +1639,9 @@ dependencies = [
name = "component_subsystem_inference_workloads"
version = "0.0.1"
dependencies = [
"actix-cors 0.6.0-beta.3",
"actix-cors 0.6.4",
"actix-http 3.3.0",
"actix-web 4.0.0-beta.10",
"actix-web 4.0.1",
"anyhow",
"base64 0.13.0",
"chrono",
@@ -1743,17 +1733,6 @@ dependencies = [
"version_check",
]
[[package]]
name = "cookie"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5f1c7727e460397e56abc4bddc1d49e07a1ad78fc98eb2e1c8f032a58a2f80d"
dependencies = [
"percent-encoding 2.2.0",
"time 0.2.26",
"version_check",
]
[[package]]
name = "cookie"
version = "0.16.2"
@@ -2453,14 +2432,14 @@ dependencies = [
name = "dummy-service"
version = "0.0.1"
dependencies = [
"actix-cors 0.6.0-beta.3",
"actix-cors 0.6.4",
"actix-files",
"actix-http 3.3.0",
"actix-multipart",
"actix-rt 2.7.0",
"actix-service 2.0.1",
"actix-utils 3.0.0",
"actix-web 4.0.0-beta.10",
"actix-web 4.0.1",
"actix-web-actors",
"actix_helpers",
"chrono",
@@ -2812,12 +2791,6 @@ dependencies = [
"errors",
]
[[package]]
name = "firestorm"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31586bda1b136406162e381a3185a506cdfc1631708dd40cba2f6628d8634499"
[[package]]
name = "flate2"
version = "1.0.26"
@@ -3391,13 +3364,13 @@ dependencies = [
[[package]]
name = "http"
version = "0.2.5"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b"
checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482"
dependencies = [
"bytes 1.3.0",
"fnv",
"itoa 0.4.7",
"itoa 1.0.3",
]
[[package]]
@@ -3452,10 +3425,10 @@ dependencies = [
name = "http_server_common"
version = "0.0.1"
dependencies = [
"actix-cors 0.6.0-beta.3",
"actix-cors 0.6.4",
"actix-http 3.3.0",
"actix-rt 2.7.0",
"actix-web 4.0.0-beta.10",
"actix-web 4.0.1",
"anyhow",
"base64 0.13.0",
"chrono",
@@ -3613,83 +3586,6 @@ dependencies = [
"unicode-normalization",
]
[[package]]
name = "image-generation-service"
version = "0.0.1"
dependencies = [
"actix",
"actix-cors 0.6.0-beta.3",
"actix-files",
"actix-http 3.3.0",
"actix-multipart",
"actix-rt 2.7.0",
"actix-service 2.0.1",
"actix-utils 3.0.0",
"actix-web 4.0.0-beta.10",
"actix-web-actors",
"anyhow",
"base64 0.13.0",
"bcrypt",
"chrono",
"cloud_storage",
"config",
"container_common",
"data-encoding",
"derive_more",
"diesel",
"dotenv",
"easyenv",
"errors",
"futures 0.1.31",
"futures 0.3.26",
"futures-util",
"google_drive_common",
"hex",
"hmac 0.10.1",
"hostname",
"http_server_common",
"hyper 0.14.24",
"infer 0.5.0",
"jobs_common",
"jwt",
"language-tags 0.3.2",
"lazy_static",
"lexical-sort",
"lfu",
"limitation",
"log",
"lru_time_cache",
"magic-crypt",
"md-5",
"memory_caching",
"mysql_queries",
"native-tls",
"once_cell",
"pulldown-cmark",
"r2d2_redis",
"rand 0.8.5",
"redis_common",
"regex",
"reqwest",
"reusable_types",
"ring 0.17.0-alpha.11",
"rust-s3",
"serde",
"serde_derive",
"serde_json",
"sha2 0.9.5",
"sqlx",
"subprocess",
"tempdir",
"time 0.2.26",
"tokio 1.25.0",
"toml",
"tts_common",
"twitch_common",
"user_input_common",
"uuid 0.8.2",
]
[[package]]
name = "indexmap"
version = "1.9.2"
@@ -3728,7 +3624,7 @@ dependencies = [
name = "inference-job"
version = "0.0.1"
dependencies = [
"actix-web 4.0.0-beta.10",
"actix-web 4.0.1",
"actix_helpers",
"anyhow",
"bootstrap",
@@ -4060,6 +3956,18 @@ version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519"
[[package]]
name = "local-channel"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f303ec0e94c6c54447f84f3b0ef7af769858a9c4ef56ef2a986d3dcd4c3fc9c"
dependencies = [
"futures-core",
"futures-sink",
"futures-util",
"local-waker",
]
[[package]]
name = "local-waker"
version = "0.1.1"
@@ -4317,25 +4225,12 @@ dependencies = [
"kernel32-sys",
"libc",
"log",
"miow 0.2.2",
"miow",
"net2",
"slab",
"winapi 0.2.8",
]
[[package]]
name = "mio"
version = "0.7.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956"
dependencies = [
"libc",
"log",
"miow 0.3.7",
"ntapi",
"winapi 0.3.9",
]
[[package]]
name = "mio"
version = "0.8.5"
@@ -4371,15 +4266,6 @@ dependencies = [
"ws2_32-sys",
]
[[package]]
name = "miow"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21"
dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "mockall"
version = "0.11.3"
@@ -4609,15 +4495,6 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
[[package]]
name = "ntapi"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44"
dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "num"
version = "0.1.42"
@@ -6653,14 +6530,14 @@ checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
name = "storyteller-web"
version = "0.0.1"
dependencies = [
"actix-cors 0.6.0-beta.3",
"actix-cors 0.6.4",
"actix-files",
"actix-http 3.3.0",
"actix-multipart",
"actix-rt 2.7.0",
"actix-service 2.0.1",
"actix-utils 3.0.0",
"actix-web 4.0.0-beta.10",
"actix-web 4.0.1",
"actix-web-actors",
"actix_helpers",
"anyhow",
@@ -6686,6 +6563,7 @@ dependencies = [
"errors",
"futures 0.1.31",
"futures 0.3.26",
"futures-core",
"futures-util",
"google_drive_common",
"hashing",
@@ -6713,6 +6591,7 @@ dependencies = [
"native-tls",
"newrelic-telemetry",
"once_cell",
"pin-project-lite 0.2.9",
"pulldown-cmark",
"r2d2_redis",
"rand 0.8.5",
@@ -7787,7 +7666,7 @@ dependencies = [
"actix-rt 2.7.0",
"actix-service 2.0.1",
"actix-utils 3.0.0",
"actix-web 4.0.0-beta.10",
"actix-web 4.0.1",
"actix-web-actors",
"anyhow",
"base64 0.13.0",
@@ -8034,7 +7913,7 @@ dependencies = [
name = "url_config"
version = "0.0.1"
dependencies = [
"actix-web 4.0.0-beta.10",
"actix-web 4.0.1",
"anyhow",
"http_server_common",
"reusable_types",
@@ -8057,7 +7936,7 @@ dependencies = [
name = "users_component"
version = "0.0.1"
dependencies = [
"actix-web 4.0.0-beta.10",
"actix-web 4.0.1",
"anyhow",
"base64 0.13.0",
"bcrypt",
@@ -8487,7 +8366,7 @@ dependencies = [
"actix-rt 2.7.0",
"actix-service 2.0.1",
"actix-utils 3.0.0",
"actix-web 4.0.0-beta.10",
"actix-web 4.0.1",
"actix-web-actors",
"anyhow",
"base64 0.13.0",
-1
View File
@@ -61,7 +61,6 @@ members = [
"crates/service/job/w2l_inference_job",
"crates/service/other/twitch_pubsub_subscriber",
"crates/service/web/dummy_service",
"crates/service/web/image_generation_service",
"crates/service/web/storyteller_web",
"crates/service/web/websocket_gateway",
@@ -1,5 +1,5 @@
use actix_http::http::HeaderMap;
use actix_web::http::HeaderName;
use actix_http::header::HeaderMap;
use actix_http::header::HeaderName;
use std::str::FromStr;
pub (crate) fn get_ip_from_header(headers: &HeaderMap, header_name: &str) -> Option<String> {
@@ -23,12 +23,12 @@ impl BannedCidrFilter {
}
}
impl<S> Transform<S, ServiceRequest> for BannedCidrFilter
impl<S, B> Transform<S, ServiceRequest> for BannedCidrFilter
where
S: Service<ServiceRequest, Response = ServiceResponse, Error = Error>,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
{
type Response = ServiceResponse;
type Response = ServiceResponse<B>;
type Error = Error;
type InitError = ();
type Transform = BannedCidrFilterMiddleware<S>;
@@ -7,26 +7,28 @@ use crate::middleware::banned_ip_filter::banned_error::BannedError;
use futures_util::future::{err, Either, Ready};
use std::net::IpAddr;
use std::str::FromStr;
use std::task::{Context, Poll};
//use std::task::{Context, Poll};
pub struct BannedCidrFilterMiddleware<S> {
pub (crate) service: S,
pub (crate) cidr_bans: BannedCidrSet,
}
impl<S> Service<ServiceRequest> for BannedCidrFilterMiddleware<S>
impl<S, B> Service<ServiceRequest> for BannedCidrFilterMiddleware<S>
where
S: Service<ServiceRequest, Response = ServiceResponse, Error = Error>,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
{
type Response = ServiceResponse;
type Response = ServiceResponse<B>;
type Error = Error;
type Future = Either<S::Future, Ready<Result<Self::Response, Self::Error>>>;
// alternatively(?), actix_service::forward_ready!(service);
fn poll_ready(&self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
self.service.poll_ready(cx)
}
//// alternatively(?), actix_service::forward_ready!(service);
//fn poll_ready(&self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
// self.service.poll_ready(cx)
//}
actix_service::forward_ready!(service);
fn call(&self, request: ServiceRequest) -> Self::Future {
let ip_address = get_service_request_ip_address(&request);
@@ -1,4 +1,4 @@
use actix_http::body::Body;
use actix_http::body::BoxBody;
use actix_http::header::CONTENT_TYPE;
use actix_web::http::StatusCode;
use actix_web::http::header::ContentType;
@@ -20,7 +20,7 @@ impl ResponseError for BannedError {
StatusCode::UNAUTHORIZED
}
fn error_response(&self) -> HttpResponse<Body> {
fn error_response(&self) -> HttpResponse<BoxBody> {
// NB: I'm setting a string error because I mistakenly got caught by this in local dev
// and couldn't figure out the issue for a bit. At least I can grep for this string.
// However, I need to balance this requirement with not cluing in those that are banned.
@@ -23,12 +23,12 @@ impl BannedIpFilter {
}
}
impl<S> Transform<S, ServiceRequest> for BannedIpFilter
impl<S, B> Transform<S, ServiceRequest> for BannedIpFilter
where
S: Service<ServiceRequest, Response = ServiceResponse, Error = Error>,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
{
type Response = ServiceResponse;
type Response = ServiceResponse<B>;
type Error = Error;
type InitError = ();
type Transform = BannedIpFilterMiddleware<S>;
@@ -5,7 +5,7 @@ use crate::extractors::get_service_request_ip_address::get_service_request_ip_ad
use crate::middleware::banned_ip_filter::banned_error::BannedError;
use crate::middleware::banned_ip_filter::ip_ban_list::ip_ban_list::IpBanList;
use futures_util::future::{err, Either, Ready};
use std::task::{Context, Poll};
//use std::task::{Context, Poll};
// There are two steps in middleware processing.
// 1. Middleware initialization, middleware factory gets called with
@@ -17,19 +17,21 @@ pub struct BannedIpFilterMiddleware<S> {
pub (crate) ip_ban_list: IpBanList,
}
impl<S> Service<ServiceRequest> for BannedIpFilterMiddleware<S>
impl<S, B> Service<ServiceRequest> for BannedIpFilterMiddleware<S>
where
S: Service<ServiceRequest, Response = ServiceResponse, Error = Error>,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
{
type Response = ServiceResponse;
type Response = ServiceResponse<B>;
type Error = Error;
type Future = Either<S::Future, Ready<Result<Self::Response, Self::Error>>>;
// alternatively(?), actix_service::forward_ready!(service);
fn poll_ready(&self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
self.service.poll_ready(cx)
}
//// alternatively(?), actix_service::forward_ready!(service);
//fn poll_ready(&self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
// self.service.poll_ready(cx)
//}
actix_service::forward_ready!(service);
fn call(&self, request: ServiceRequest) -> Self::Future {
let ip_address = get_service_request_ip_address(&request);
@@ -23,12 +23,12 @@ impl DisabledEndpointFilter {
}
}
impl<S> Transform<S, ServiceRequest> for DisabledEndpointFilter
impl<S, B> Transform<S, ServiceRequest> for DisabledEndpointFilter
where
S: Service<ServiceRequest, Response = ServiceResponse, Error = Error>,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
{
type Response = ServiceResponse;
type Response = ServiceResponse<B>;
type Error = Error;
type InitError = ();
type Transform = DisabledEndpointFilterMiddleware<S>;
@@ -4,7 +4,7 @@ use actix_web::dev::{ServiceRequest, ServiceResponse};
use crate::middleware::disabled_endpoint_filter::disabled_endpoints::disabled_endpoints::DisabledEndpoints;
use crate::middleware::disabled_endpoint_filter::disabled_error::DisabledError;
use futures_util::future::{err, Either, Ready};
use std::task::{Context, Poll};
//use std::task::{Context, Poll};
// There are two steps in middleware processing.
// 1. Middleware initialization, middleware factory gets called with
@@ -16,19 +16,21 @@ pub struct DisabledEndpointFilterMiddleware<S> {
pub (crate) disabled_endpoints: DisabledEndpoints,
}
impl<S> Service<ServiceRequest> for DisabledEndpointFilterMiddleware<S>
impl<S, B> Service<ServiceRequest> for DisabledEndpointFilterMiddleware<S>
where
S: Service<ServiceRequest, Response = ServiceResponse, Error = Error>,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
{
type Response = ServiceResponse;
type Response = ServiceResponse<B>;
type Error = Error;
type Future = Either<S::Future, Ready<Result<Self::Response, Self::Error>>>;
// alternatively(?), actix_service::forward_ready!(service);
fn poll_ready(&self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
self.service.poll_ready(cx)
}
//// alternatively(?), actix_service::forward_ready!(service);
//fn poll_ready(&self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
// self.service.poll_ready(cx)
//}
actix_service::forward_ready!(service);
fn call(&self, request: ServiceRequest) -> Self::Future {
let endpoint = request.path();
@@ -1,4 +1,4 @@
use actix_http::body::Body;
use actix_http::body::BoxBody;
use actix_http::header::CONTENT_TYPE;
use actix_web::http::StatusCode;
use actix_web::http::header::ContentType;
@@ -20,7 +20,7 @@ impl ResponseError for DisabledError {
StatusCode::TOO_MANY_REQUESTS
}
fn error_response(&self) -> HttpResponse<Body> {
fn error_response(&self) -> HttpResponse<BoxBody> {
// NB: I'm setting a string error because I mistakenly got caught by this in local dev
// and couldn't figure out the issue for a bit. At least I can grep for this string.
// However, I need to balance this requirement with not cluing in those that are banned.
+11 -14
View File
@@ -3,7 +3,6 @@ use actix_service::ServiceFactory;
use actix_web::dev::{Handler, ServiceRequest, ServiceResponse};
use actix_web::error::Error;
use actix_web::{App, web, HttpResponse, FromRequest, Responder};
use std::future::Future;
// TODO: Check that routes don't overlap.
// TODO: Properly handle scoped routes in a nice DSL.
@@ -21,7 +20,7 @@ where
InitError = (),
>,
{
app: App<T, B>,
app: App<T>,
}
impl <T, B> RouteBuilder<T, B>
@@ -36,24 +35,23 @@ impl <T, B> RouteBuilder<T, B>
>,
{
/// Constructor
pub fn from_app(app: App<T, B>) -> Self {
pub fn from_app(app: App<T>) -> Self {
Self {
app
}
}
/// Return back to Actix App.
pub fn into_app(self) -> App<T, B> {
pub fn into_app(self) -> App<T> {
self.app
}
/// Add an HTTP GET route. This also adds the HEAD request for CORS.
pub fn add_get<F, S, R>(mut self, path: &str, handler: F) -> Self
pub fn add_get<F, Args>(mut self, path: &str, handler: F) -> Self
where
F: Handler<S, R>,
S: FromRequest + 'static,
R: Future + 'static,
R::Output: Responder + 'static,
F: Handler<Args>,
Args: FromRequest + 'static,
F::Output: Responder + 'static,
{
self.app = self.app.service(
web::resource(path)
@@ -64,12 +62,11 @@ impl <T, B> RouteBuilder<T, B>
}
/// Add an HTTP POST route. This also adds the HEAD request for CORS.
pub fn add_post<F, S, R>(mut self, path: &str, handler: F) -> Self
pub fn add_post<F, Args>(mut self, path: &str, handler: F) -> Self
where
F: Handler<S, R>,
S: FromRequest + 'static,
R: Future + 'static,
R::Output: Responder + 'static,
F: Handler<Args>,
Args: FromRequest + 'static,
F::Output: Responder + 'static,
{
self.app = self.app.service(
web::resource(path)
@@ -1,5 +1,4 @@
use actix_cors::Cors;
use actix_http::http;
use log::info;
use reusable_types::server_environment::ServerEnvironment;
@@ -38,11 +37,11 @@ fn do_build_cors_config(is_production: bool) -> Cors {
cors.allowed_methods(vec!["GET", "POST", "OPTIONS", "DELETE"])
.supports_credentials()
.allowed_headers(vec![
http::header::ACCEPT,
http::header::ACCESS_CONTROL_ALLOW_ORIGIN, // Tabulator Ajax
http::header::CONTENT_TYPE,
http::header::ACCESS_CONTROL_ALLOW_CREDENTIALS, // https://stackoverflow.com/a/46412839
http::header::HeaderName::from_static("x-requested-with") // Tabulator Ajax sends
actix_http::header::ACCEPT,
actix_http::header::ACCESS_CONTROL_ALLOW_ORIGIN, // Tabulator Ajax
actix_http::header::CONTENT_TYPE,
actix_http::header::ACCESS_CONTROL_ALLOW_CREDENTIALS, // https://stackoverflow.com/a/46412839
actix_http::header::HeaderName::from_static("x-requested-with") // Tabulator Ajax sends
])
.max_age(3600)
}
@@ -204,6 +203,7 @@ pub fn add_development_only(cors: Cors) -> Cors {
#[cfg(test)]
mod tests {
use actix_cors::Cors;
use actix_http::body::{BoxBody, EitherBody};
use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
use actix_web::http::StatusCode;
use actix_web::test::TestRequest;
@@ -212,7 +212,7 @@ mod tests {
use reusable_types::server_environment::ServerEnvironment;
use speculoos::{assert_that, asserting};
async fn make_test_request(cors: &Cors, hostname: &str) -> ServiceResponse {
async fn make_test_request(cors: &Cors, hostname: &str) -> ServiceResponse<EitherBody<BoxBody>> {
let cors= cors.new_transform(test::ok_service())
.await
.unwrap();
@@ -1,4 +1,4 @@
use actix_http::http::StatusCode;
use actix_http::StatusCode;
use actix_web::HttpResponse;
@@ -30,9 +30,9 @@ struct SimpleGenericJsonError {
#[cfg(test)]
mod tests {
use actix_http::body::{BoxBody, MessageBody};
use crate::error::simple_json_error_response::simple_json_error_response;
use actix_web::http::StatusCode;
use actix_http::body::AnyBody;
#[test]
pub fn serialization() {
@@ -43,13 +43,10 @@ mod tests {
assert_eq!(response.status(), StatusCode::TOO_MANY_REQUESTS);
let body = response.into_body();
match body {
AnyBody::Bytes(bytes) => {
let bytes = bytes.to_vec();
let body = String::from_utf8(bytes).unwrap();
assert_eq!(body, "{\"success\":false,\"error_reason\":\"foo\"}");
}
_ => panic!("this failed"),
}
let bytes = body.try_into_bytes().expect("bytes should extract");
let body = String::from_utf8(bytes.to_vec()).unwrap();
assert_eq!(body, "{\"success\":false,\"error_reason\":\"foo\"}");
}
}
@@ -1,6 +1,7 @@
use actix_http::header::HeaderMap;
use actix_http::header::HeaderName;
use actix_web::HttpRequest;
use actix_web::dev::ServiceRequest;
use actix_web::http::{HeaderMap, HeaderName};
use log::debug;
use std::str::FromStr;
@@ -1,6 +1,5 @@
use anyhow::anyhow;
use errors::AnyhowResult;
use log::error;
use once_cell::sync::Lazy;
use regex::Regex;
use sqlx::MySqlPool;
+1 -1
View File
@@ -173,7 +173,7 @@ mod tests {
use once_cell::sync::Lazy;
use crate::clean_symbols::clean_symbols;
const TIME_BOMB_EPOCH_STR : &'static str = "2023-06-01T00:00:00.00Z";
const TIME_BOMB_EPOCH_STR : &'static str = "2023-11-01T00:00:00.00Z";
static TIME_BOMB_EPOCH: Lazy<DateTime<Utc>> = Lazy::new(|| {
let datetime = DateTime::parse_from_rfc3339(TIME_BOMB_EPOCH_STR)
@@ -11,7 +11,7 @@ use crate::stripe::http_endpoints::customer_portal::stripe_create_customer_porta
use crate::stripe::http_endpoints::webhook::stripe_webhook_handler::stripe_webhook_handler;
use crate::users::http_endpoints::list_active_user_subscriptions_handler::list_active_user_subscriptions_handler;
pub fn add_suggested_stripe_billing_routes<T, B> (app: App<T, B>) -> App<T, B>
pub fn add_suggested_stripe_billing_routes<T, B> (app: App<T>) -> App<T>
where
B: MessageBody,
T: ServiceFactory<
@@ -11,7 +11,7 @@ use crate::endpoints::session_info_handler::session_info_handler;
// NB: This does not include the user edit endpoints since FakeYou's API mounts them alongside other things.
// A 'v2' API would mount under a v2 prefix and the entity type.
pub fn add_suggested_api_v1_account_creation_and_session_routes<T, B> (app: App<T, B>) -> App<T, B>
pub fn add_suggested_api_v1_account_creation_and_session_routes<T, B> (app: App<T>) -> App<T>
where
B: MessageBody,
T: ServiceFactory<
@@ -52,7 +52,7 @@ pub async fn logout_handler(
mysql_pool: web::Data<MySqlPool>,
) -> Result<HttpResponse, LogoutError>
{
let delete_cookie = match http_request.cookie("session") {
let mut delete_cookie = match http_request.cookie("session") {
Some(cookie) => {
match session_cookie_manager.decode_session_token(&cookie) {
Err(e) => {
@@ -77,8 +77,11 @@ pub async fn logout_handler(
let body = serde_json::to_string(&response)
.map_err(|_e| LogoutError::ServerError)?;
// Mark cookie for deletion
delete_cookie.make_removal();
Ok(HttpResponse::Ok()
.del_cookie(&delete_cookie)
.cookie(delete_cookie)
.content_type("application/json")
.body(body))
}
@@ -14,7 +14,6 @@ use jwt::VerifyWithKey;
use log::warn;
use sha2::Sha256;
use std::collections::BTreeMap;
use time::OffsetDateTime;
/**
* Cookie version history
@@ -80,9 +79,11 @@ impl SessionCookieManager {
}
pub fn delete_cookie(&self) -> Cookie {
Cookie::build(SESSION_COOKIE_NAME, "DELETED")
.expires(OffsetDateTime::unix_epoch())
.finish()
let mut cookie = Cookie::build(SESSION_COOKIE_NAME, "DELETED")
.expires(actix_web::cookie::time::OffsetDateTime::UNIX_EPOCH)
.finish();
cookie.make_removal();
cookie
}
pub fn decode_session_cookie_payload(&self, session_cookie: &Cookie)
@@ -1,130 +0,0 @@
[package]
publish = false
name = "image-generation-service"
edition = "2018"
version = "0.0.1"
authors = [
"Brandon Thomas <bt@brand.io>",
"Brandon Thomas <echelon@gmail.com>",
]
# Main server monolith
[[bin]]
name = "image-generation-service"
path = "src/main.rs"
[dependencies]
# Internal
cloud_storage = { path = "../../../lib/api_clients/cloud_storage" }
config = { path = "../../../lib/deprecated/config" }
container_common = { path = "../../../lib/deprecated/container_common" }
errors = { path = "../../../lib/errors" }
google_drive_common = { path = "../../../lib/api_clients/google_drive_common" }
http_server_common = { path = "../../../lib/deprecated/http_server_common" }
jobs_common = { path = "../../../lib/jobs_common" }
memory_caching = { path = "../../../lib/caching/memory_caching" }
mysql_queries = { path = "../../../lib/mysql_queries" }
redis_common = { path = "../../../lib/redis_common" }
reusable_types = { path = "../../../_types/reusable_types" }
tts_common = { path = "../../../lib/tts_common" }
twitch_common = { path = "../../../lib/api_clients/twitch_common" }
user_input_common = { path = "../../../lib/user_input_common" }
# External
anyhow = "1.0.40"
base64 = "0.13.0"
chrono = { version = "0.4.19", features = ["serde"] }
derive_more = "0.99.14"
dotenv = "0.15.0"
easyenv = "0.0.9"
hex = "0.4.3"
hostname = "0.3.1"
lazy_static = "1.4.0"
lexical-sort = "0.3.1"
lfu = "0.2.5"
log = "0.4.14"
once_cell = "1.9.0"
rand = "0.8.3"
regex = "1.5.4"
time = "0.2.26"
uuid = { version = "0.8.2", features = ["v4"] }
# Language tag parsing
# TODO: Move to language support crate
language-tags = "0.3.2" # Parsing single tags richly
# HTTP
# TODO/NB: This is just for Twitch, but we might need it later.
reqwest = { version = "0.11.4" }
native-tls = "0.2.8"
# Runtime
# NB: We switched to Tokio from `async-std` for broader ecosystem support.
tokio = { version = "1.6.0", features = ["macros"] }
# Futures
futures = { version = "0.3.17", features = ["thread-pool"] } # feature for ThreadPool
futures-util = "0.3.9"
futures_old_for_limiter = { package = "futures", version = "0.1.29" } # Older version of futures for `limiter` crate
# MySql Database
# "offline" supports typesafe builds without a live database
# "rustls" doesn't appear to work with IP addresses, per:
# https://github.com/launchbadge/sqlx/issues/1095#issuecomment-798050828
sqlx = { version = "0.6.2", features = [ "mysql", "runtime-actix-native-tls", "offline", "chrono" ] }
# Redis Database
limitation = "0.1.1" # Redis rate limiter
r2d2_redis = "0.14.0"
# In-memory caching
lru_time_cache = "0.11.11"
# Files
data-encoding = "2.3.2"
ring = "0.17.0-alpha.10"
infer = "0.5.0"
# The "never-encode-slash" feature seems to have been removed:
# https://github.com/durch/rust-s3/pull/254
rust-s3 = { version = "0.32.3" }
subprocess = "0.2.6"
tempdir = "0.3.7"
actix = "0.12.0"
actix-cors = "0.6.0-beta.3"
actix-files= "0.6.0-beta.8"
actix-http = "3.0.0-beta.11"
actix-multipart = "0.4.0-beta.7"
actix-rt = "2.4.0"
actix-service = "2.0.1"
actix-utils = "3.0.0"
actix-web = "4.0.0-beta.10"
actix-web-actors = "4.0.0-beta.7"
jwt = "0.13.0"
# NB: Hyper is just for HTTP client use in jobs. I'd use Actix client, but I need tokio runtime
# NB: Furthermore, the Tokio runtime is old, so I have to use an older Hyper.
hyper = { version = "0.14.14" }
# Crypto
bcrypt = "0.8" # password hashes
hmac = "0.10.0" # cookies
magic-crypt = "3.1.8" # encrypting sort IDs for the frontend so we don't leak info
md-5 = "0.9.1" # gravatar
sha2 = "0.9.5" # file hashes, inference text hashes, etc.
# Serialization
serde = "1.0.125"
serde_derive = "1.0.125"
serde_json = "1.0.64"
toml = "0.5.8"
# Text processing
pulldown-cmark = "0.8.0"
[build-dependencies]
# NB: Only using diesel for migrations support
diesel = { version = "1.4.6", features = ["mysql"] }
@@ -1,247 +0,0 @@
// Never allow these
#![forbid(private_in_public)]
#![forbid(unused_must_use)] // NB: It's unsafe to not close/check some things
// Okay to toggle
//#![forbid(warnings)]
#![allow(unreachable_patterns)]
#![allow(unused_imports)]
#![allow(unused_mut)]
#![allow(unused_variables)]
// Always allow
#![allow(dead_code)]
#![allow(non_snake_case)]
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate magic_crypt;
#[macro_use] extern crate serde_derive;
mod routes;
mod server_state;
use actix_web::middleware::{DefaultHeaders, Logger};
use actix_web::{App, HttpServer, web};
use cloud_storage::bucket_client::BucketClient;
use config::common_env::CommonEnv;
use config::shared_constants::{DEFAULT_MYSQL_CONNECTION_STRING, DEFAULT_RUST_LOG};
use errors::AnyhowResult;
use crate::routes::add_routes;
use crate::server_state::{EnvConfig, InMemoryCaches, ServerState};
use http_server_common::cors::build_production_cors_config;
use limitation::Limiter;
use log::info;
use memory_caching::single_item_ttl_cache::SingleItemTtlCache;
use r2d2_redis::{r2d2, RedisConnectionManager};
use sqlx::mysql::MySqlPoolOptions;
use std::sync::Arc;
use std::time::Duration;
use tokio::runtime::Runtime;
const DEFAULT_BIND_ADDRESS : &'static str = "0.0.0.0:12345";
#[actix_web::main]
async fn main() -> AnyhowResult<()> {
easyenv::init_all_with_default_logging(Some(DEFAULT_RUST_LOG));
// NB: Do not check this secrets-containing dotenv file into VCS.
// This file should only contain *development* secrets, never production.
let _ = dotenv::from_filename(".env-secrets").ok();
let common_env = CommonEnv::read_from_env()?; // TODO: Deprecate and remove
info!("Obtaining hostname...");
let server_hostname = hostname::get()
.ok()
.and_then(|h| h.into_string().ok())
.unwrap_or("image-generation-service".to_string());
info!("Hostname: {}", &server_hostname);
info!("Connecting to database...");
let db_connection_string =
easyenv::get_env_string_or_default(
"MYSQL_URL",
DEFAULT_MYSQL_CONNECTION_STRING);
let pool = MySqlPoolOptions::new()
.max_connections(easyenv::get_env_num("MYSQL_MAX_CONNECTIONS", 5)?)
.connect(&db_connection_string)
.await?;
// let firehose_publisher = FirehosePublisher {
// mysql_pool: pool.clone(), // NB: Pool is clone/sync/send-safe
// };
//
// let badge_granter = BadgeGranter {
// mysql_pool: pool.clone(), // NB: Pool is clone/sync/send-safe
// firehose_publisher: firehose_publisher.clone(), // NB: Also safe
// };
let redis_manager = RedisConnectionManager::new(
common_env.redis_0_connection_string.clone())?;
let redis_pool = r2d2::Pool::builder()
.build(redis_manager)?;
info!("Setting up Redis rate limiters...");
//let logged_out_redis_rate_limiter = {
// let limiter_enabled = easyenv::get_env_bool_or_default("LIMITER_LOGGED_OUT_ENABLED", true);
// let limiter_max_requests = easyenv::get_env_num("LIMITER_LOGGED_OUT_MAX_REQUESTS", 3)?;
// let limiter_window_seconds = easyenv::get_env_num("LIMITER_LOGGED_OUT_WINDOW_SECONDS", 10)?;
//
// let limiter = Limiter::build(&common_env.redis_0_connection_string)
// .limit(limiter_max_requests)
// .period(Duration::from_secs(limiter_window_seconds))
// .finish()?;
//
// RedisRateLimiter::new(limiter, "logged_out", limiter_enabled)
//};
//let logged_in_redis_rate_limiter = {
// let limiter_enabled = easyenv::get_env_bool_or_default("LIMITER_LOGGED_IN_ENABLED", true);
// let limiter_max_requests = easyenv::get_env_num("LIMITER_LOGGED_IN_MAX_REQUESTS", 3)?;
// let limiter_window_seconds = easyenv::get_env_num("LIMITER_LOGGED_IN_WINDOW_SECONDS", 10)?;
//
// let limiter = Limiter::build(&common_env.redis_0_connection_string)
// .limit(limiter_max_requests)
// .period(Duration::from_secs(limiter_window_seconds))
// .finish()?;
//
// RedisRateLimiter::new(limiter, "logged_in", limiter_enabled)
//};
//let api_high_priority_redis_rate_limiter = {
// let limiter_enabled = easyenv::get_env_bool_or_default("LIMITER_API_HIGH_PRIORITY_ENABLED", true);
// let limiter_max_requests = easyenv::get_env_num("LIMITER_API_HIGH_PRIORITY_MAX_REQUESTS", 30)?;
// let limiter_window_seconds = easyenv::get_env_num("LIMITER_API_HIGH_PRIORITY_WINDOW_SECONDS", 30)?;
//
// let limiter = Limiter::build(&common_env.redis_0_connection_string)
// .limit(limiter_max_requests)
// .period(Duration::from_secs(limiter_window_seconds))
// .finish()?;
//
// RedisRateLimiter::new(limiter, "api_high_priority", limiter_enabled)
//};
//let model_upload_rate_limiter = {
// let limiter_enabled = easyenv::get_env_bool_or_default("LIMITER_MODEL_UPLOAD_ENABLED", true);
// let limiter_max_requests = easyenv::get_env_num("LIMITER_MODEL_UPLOAD_MAX_REQUESTS", 3)?;
// let limiter_window_seconds = easyenv::get_env_num("LIMITER_MODEL_UPLOAD_WINDOW_SECONDS", 10)?;
//
// let limiter = Limiter::build(&common_env.redis_0_connection_string)
// .limit(limiter_max_requests)
// .period(Duration::from_secs(limiter_window_seconds))
// .finish()?;
//
// RedisRateLimiter::new(limiter, "model_upload", limiter_enabled)
//};
info!("Reading env vars and setting up utils...");
let bind_address = easyenv::get_env_string_or_default("BIND_ADDRESS", DEFAULT_BIND_ADDRESS);
let num_workers = easyenv::get_env_num("NUM_WORKERS", 8)?;
let hmac_secret = easyenv::get_env_string_or_default("COOKIE_SECRET", "notsecret");
let cookie_domain = easyenv::get_env_string_or_default("COOKIE_DOMAIN", ".vo.codes");
let cookie_secure = easyenv::get_env_bool_or_default("COOKIE_SECURE", true);
let cookie_http_only = easyenv::get_env_bool_or_default("COOKIE_HTTP_ONLY", true);
let website_homepage_redirect =
easyenv::get_env_string_or_default("WEBSITE_HOMEPAGE_REDIRECT", "https://vo.codes/");
//let cookie_manager = CookieManager::new(&cookie_domain, &hmac_secret);
//let session_checker = SessionChecker::new(&cookie_manager);
let access_key = easyenv::get_env_string_required("ACCESS_KEY")?;
let secret_key = easyenv::get_env_string_required("SECRET_KEY")?;
let region_name = easyenv::get_env_string_required("REGION_NAME")?;
// NB: This secret really isn't too important.
// We can even rotate it without too much impact to users.
//let sort_key_crypto_secret =
// easyenv::get_env_string_or_default("SORT_KEY_SECRET", "webscale");
//let sort_key_crypto = SortKeyCrypto::new(&sort_key_crypto_secret);
// Background jobs.
// let health_check_status = HealthCheckStatus::new();
// let health_check_status2 = health_check_status.clone();
// let ip_banlist = IpBanlistSet::new();
// let ip_banlist2 = ip_banlist.clone();
// let mysql_pool3 = pool.clone();
// let mysql_pool4 = pool.clone();
let tokio_runtime = Runtime::new()?;
// info!("Spawning DB health checker thread.");
//
// tokio_runtime.spawn(async {
// db_health_checker_thread(health_check_status2, mysql_pool3).await;
// });
//
// info!("Spawning IP ban polling thread.");
//
// tokio_runtime.spawn(async {
// poll_ip_bans(ip_banlist2, mysql_pool4).await;
// });
let server_state = ServerState {
env_config: EnvConfig {
num_workers,
bind_address,
cookie_domain,
cookie_secure,
cookie_http_only,
website_homepage_redirect,
},
hostname: server_hostname,
mysql_pool: pool,
redis_pool,
caches: InMemoryCaches {
},
};
serve(server_state)
.await?;
Ok(())
}
pub async fn serve(server_state: ServerState) -> AnyhowResult<()>
{
let bind_address = server_state.env_config.bind_address.clone();
let num_workers = server_state.env_config.num_workers.clone();
let hostname = server_state.hostname.clone();
let server_state_arc = web::Data::new(Arc::new(server_state));
info!("Starting HTTP service.");
let log_format = "[%{HOSTNAME}e] %a \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\" %T";
HttpServer::new(move || {
// NB: Safe to clone due to internal arc
//let ip_banlist = server_state_arc.ip_banlist.clone();
let build_sha = std::fs::read_to_string("/GIT_SHA").unwrap_or(String::from("unknown"));
let app = App::new()
.app_data(server_state_arc.clone())
.wrap(build_production_cors_config())
.wrap(DefaultHeaders::new()
.header("X-Backend-Hostname", &hostname)
.header("X-Build-Sha", build_sha.trim()))
//.wrap(IpFilter::new(ip_banlist))
.wrap(Logger::new(&log_format)
.exclude("/liveness")
.exclude("/readiness"));
add_routes(app)
})
.bind(bind_address)?
.workers(num_workers)
.run()
.await?;
Ok(())
}
@@ -1,29 +0,0 @@
use actix_http::body::MessageBody;
use actix_service::ServiceFactory;
use actix_web::dev::{ServiceRequest, ServiceResponse};
use actix_web::error::Error;
use actix_web::{App, web, HttpResponse};
use http_server_common::endpoints::default_route_404::default_route_404;
use http_server_common::endpoints::root_index::get_root_index;
pub fn add_routes<T, B> (app: App<T, B>) -> App<T, B>
where
B: MessageBody,
T: ServiceFactory<
ServiceRequest,
Config = (),
Response = ServiceResponse<B>,
Error = Error,
InitError = (),
>,
{
app
//.service(web::resource("/_status")
// .route(web::get().to(get_health_check_handler))
// .route(web::head().to(|| HttpResponse::Ok())))
.service(web::resource("/")
.route(web::get().to(get_root_index))
.route(web::head().to(|| HttpResponse::Ok()))
)
.default_service( web::route().to(default_route_404))
}
@@ -1,59 +0,0 @@
use r2d2_redis::{r2d2, RedisConnectionManager};
use sqlx::MySqlPool;
/// State that is injected into every endpoint.
pub struct ServerState {
pub env_config: EnvConfig,
pub hostname: String,
//pub health_check_status: HealthCheckStatus,
pub mysql_pool: MySqlPool,
pub redis_pool: r2d2::Pool<RedisConnectionManager>,
//pub redis_rate_limiters: RedisRateLimiters,
//pub cookie_manager: CookieManager,
//pub session_checker: SessionChecker,
//pub sort_key_crypto: SortKeyCrypto,
//pub ip_banlist: IpBanlistSet,
pub caches: InMemoryCaches,
}
#[derive(Clone)]
pub struct EnvConfig {
// Number of thread workers.
pub num_workers: usize,
pub bind_address: String,
pub cookie_domain: String,
pub cookie_secure: bool,
pub cookie_http_only: bool,
pub website_homepage_redirect: String,
}
/// Different rate limiters for different users
//#[derive(Clone)]
//pub struct RedisRateLimiters {
// /// Logged out users have stricter limits
// pub logged_out: RedisRateLimiter,
//
// /// Logged in users have a little more leeway
// pub logged_in: RedisRateLimiter,
//
// /// API consumers have even higher priority
// /// (Temporary for VidVoice.ai; a long term solution builds an in-memory cache
// /// of these or finds a better rate limit library that allows on-demand rate
// /// constructions)
// pub api_high_priority: RedisRateLimiter,
//}
/// In-memory caches
#[derive(Clone)]
pub struct InMemoryCaches {
}
@@ -96,6 +96,8 @@ tokio = { version = "1.6.0", features = ["macros"] }
futures = { version = "0.3.17", features = ["thread-pool"] } # feature for ThreadPool
futures-util = "0.3.9"
futures_old_for_limiter = { package = "futures", version = "0.1.29" } # Older version of futures for `limiter` crate
futures-core = "0.3.26" # NB: For middleware/futures upgrade
pin-project-lite = "0.2.9" # NB: For middleware/futures upgrade
# MySql Database
# "offline" supports typesafe builds without a live database
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,17 +1,17 @@
use actix_http::header;
use actix_http::http::StatusCode;
use actix_web::cookie::Cookie;
use actix_web::cookie::time::OffsetDateTime;
use actix_web::http::StatusCode;
use actix_web::web::Query;
use actix_web::{HttpResponse, HttpRequest, Responder, get, web, HttpMessage};
use crate::http_server::endpoints::investor_demo::default_redirect::{DEFAULT_INVESTOR_REDIRECT, redirect_is_allowed};
use crate::http_server::endpoints::investor_demo::demo_cookie::STORYTELLER_DEMO_COOKIE_NAME;
use crate::server_state::ServerState;
use http_server_common::request::get_request_host::get_request_host;
use hyper::header::LOCATION;
use log::info;
use std::ops::Deref;
use std::sync::Arc;
use time::OffsetDateTime;
use http_server_common::request::get_request_host::get_request_host;
#[derive(Deserialize)]
pub struct QueryFields {
@@ -48,7 +48,7 @@ pub async fn disable_demo_mode_handler(
// Kill the cookie
let mut cookie_builder = Cookie::build(STORYTELLER_DEMO_COOKIE_NAME, "")
.secure(server_state.env_config.cookie_secure) // HTTPS-only
.expires(OffsetDateTime::unix_epoch())
.expires(OffsetDateTime::UNIX_EPOCH)
.http_only(false) // This is meant to be exposed to Javascript!
// NB: Since we're setting this from direct HTTP access rather than XHR, the browser
// implicitly sets the path used to access the cookie, ie. '/demo_mode', which is not what
@@ -60,10 +60,11 @@ pub async fn disable_demo_mode_handler(
cookie_builder = cookie_builder.domain(cookie_domain);
}
let cookie = cookie_builder.finish();
let mut cookie = cookie_builder.finish();
cookie.make_removal(); // Remove the cookie
HttpResponse::build(StatusCode::FOUND)
.append_header((header::LOCATION, safe_redirect_url.to_string()))
.del_cookie(&cookie)
.cookie(cookie)
.finish()
}
@@ -1,17 +1,16 @@
use actix_http::header;
use actix_http::http::StatusCode;
use actix_web::cookie::Cookie;
use actix_web::http::StatusCode;
use actix_web::web::Query;
use actix_web::{HttpResponse, HttpRequest, Responder, get, web, HttpMessage};
use crate::http_server::endpoints::investor_demo::default_redirect::{DEFAULT_INVESTOR_REDIRECT, redirect_is_allowed};
use crate::http_server::endpoints::investor_demo::demo_cookie::STORYTELLER_DEMO_COOKIE_NAME;
use crate::server_state::ServerState;
use hyper::header::LOCATION;
use http_server_common::request::get_request_host::get_request_host;
use log::info;
use std::ops::Deref;
use std::sync::Arc;
use time::OffsetDateTime;
use http_server_common::request::get_request_host::get_request_host;
#[derive(Deserialize)]
pub struct QueryFields {
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,4 +1,3 @@
use actix_http::http::StatusCode;
use actix_web::{HttpResponse, HttpRequest, Responder, get};
use log::warn;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,10 +1,9 @@
use actix_web::cookie::Cookie;
use actix_http::http::StatusCode;
use actix_web::http::header::LOCATION;
use actix_web::web::Query;
use actix_web::{HttpResponse, HttpRequest, Responder, get, web, HttpMessage};
use crate::http_server::endpoints::misc::alpha_cookie::alpha_cookie;
use crate::server_state::ServerState;
use hyper::header::LOCATION;
use log::info;
use std::ops::Deref;
use std::sync::Arc;
@@ -1,5 +1,5 @@
use actix_web::cookie::Cookie;
use actix_http::http::StatusCode;
use actix_web::http::StatusCode;
use actix_web::web::Query;
use actix_web::{HttpResponse, HttpRequest, Responder, get, web, HttpMessage};
use crate::http_server::endpoints::misc::alpha_cookie::{ALPHA_COOKIE_NAME, alpha_cookie};
@@ -26,7 +26,7 @@ pub async fn enable_alpha_handler(http_request: HttpRequest,
{
info!("GET /alpha");
let cookie = alpha_cookie(&server_state);
let mut cookie = alpha_cookie(&server_state);
match query.enable {
None => {
@@ -45,9 +45,11 @@ pub async fn enable_alpha_handler(http_request: HttpRequest,
ALPHA_COOKIE_NAME, ENABLE_LINK, DISABLE_LINK, STATUS_LINK))
}
Some(false) => {
cookie.make_removal(); // Delete cookie
HttpResponse::build(StatusCode::OK)
.content_type(CONTENT_TYPE)
.del_cookie(&cookie)
.cookie(cookie)
.body(format!("<h1>Vocodes 2.0</h1><h2>unsetting `{}` cookie</h2> {} | {} | {}",
ALPHA_COOKIE_NAME, ENABLE_LINK, DISABLE_LINK, STATUS_LINK))
}
@@ -1,7 +1,7 @@
use actix_http::http::StatusCode;
use actix_web::Error;
use actix_web::Responder;
use actix_web::Result;
use actix_web::http::StatusCode;
use actix_web::web::Data;
use actix_web::{HttpResponse, HttpRequest, get};
use crate::server_state::ServerState;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::cookie::Cookie;
use actix_web::HttpResponseBuilder;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::cookie::Cookie;
use actix_web::HttpResponseBuilder;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::cookie::Cookie;
use actix_web::HttpResponseBuilder;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::cookie::Cookie;
use actix_web::HttpResponseBuilder;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::cookie::Cookie;
use actix_web::HttpResponseBuilder;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,5 +1,4 @@
use actix_http::Error;
use actix_http::http::header;
use actix_web::HttpResponseBuilder;
use actix_web::cookie::Cookie;
use actix_web::error::ResponseError;
@@ -1,9 +1,9 @@
use actix_http::StatusCode;
use actix_http::http::{header, HeaderMap, HeaderValue};
use actix_http::{error, body::Body, Response};
use actix_http::body::BoxBody;
use actix_http::header::HeaderName;
use actix_http::{error, Response};
use actix_web::dev::{Service, Transform};
use actix_web::dev::{ServiceRequest, ServiceResponse};
use actix_web::http::HeaderName;
use actix_web::http::header::USER_AGENT;
use actix_web::web::{BytesMut, Buf, BufMut};
use actix_web::{Error, HttpResponse};
@@ -11,11 +11,16 @@ use actix_web::{ResponseError, HttpMessage, HttpRequest, HttpResponseBuilder};
use crate::http_server::web_utils::response_error_helpers::to_simple_json_error;
use crate::server_state::StaticFeatureFlags;
use errors::AnyhowResult;
use futures_core::ready;
use futures_util::future::{err, ok, Either, Ready};
use http_server_common::request::get_request_ip::get_service_request_ip;
use std::io::Write;
use std::task::{Context, Poll};
use log::warn;
use pin_project_lite::pin_project;
use std::future::Future;
use std::io::Write;
use std::marker::PhantomData;
use std::pin::Pin;
use std::task::{Context, Poll};
// There are two steps in middleware processing.
// 1. Middleware initialization, middleware factory gets called with
@@ -39,7 +44,7 @@ impl ResponseError for PushbackError {
StatusCode::TOO_MANY_REQUESTS
}
fn error_response(&self) -> HttpResponse<Body> {
fn error_response(&self) -> HttpResponse<BoxBody> {
// NB: I'm setting a string error code because I mistakenly got caught by this in local dev
// and couldn't figure out the issue for a bit. At least I can grep for this string.
// However, I need to balance this requirement with not cluing in those that are banned.
@@ -62,12 +67,12 @@ impl PushbackFilter {
}
}
impl<S> Transform<S, ServiceRequest> for PushbackFilter
impl<S, B> Transform<S, ServiceRequest> for PushbackFilter
where
S: Service<ServiceRequest, Response = ServiceResponse, Error = Error>,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
{
type Response = ServiceResponse;
type Response = ServiceResponse<B>;
type Error = Error;
type InitError = ();
type Transform = PushbackFilterMiddleware<S>;
@@ -83,19 +88,21 @@ pub struct PushbackFilterMiddleware<S> {
feature_flags: StaticFeatureFlags,
}
impl<S> Service<ServiceRequest> for PushbackFilterMiddleware<S>
impl<S, B> Service<ServiceRequest> for PushbackFilterMiddleware<S>
where
S: Service<ServiceRequest, Response = ServiceResponse, Error = Error>,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
{
type Response = ServiceResponse;
type Response = ServiceResponse<B>;
type Error = Error;
type Future = Either<S::Future, Ready<Result<Self::Response, Self::Error>>>;
// alternatively(?), actix_service::forward_ready!(service);
fn poll_ready(&self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
self.service.poll_ready(cx)
}
//// alternatively(?), actix_service::forward_ready!(service);
//fn poll_ready(&self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
// self.service.poll_ready(cx)
//}
actix_service::forward_ready!(service);
fn call(&self, req: ServiceRequest) -> Self::Future {
// NB: Ordinarily the filter should be disabled.
@@ -1,7 +1,5 @@
use actix_http::http::HeaderMap;
use actix_http::http::HeaderName;
use actix_http::header::{HeaderMap, HeaderName};
use actix_web::HttpRequest;
use actix_web::http::HeaderValue;
use errors::AnyhowResult;
// NB: This is extracted because CLion is having incredible difficulty with these types.
@@ -1,7 +1,7 @@
//! NB: This doesn't live in the `util.redis` package because it depends on `http_server`.
//! It's only used for the server anyway, so living here makes sense.
use actix_http::http::{HeaderName, HeaderMap};
use actix_http::header::HeaderName;
use actix_web::HttpRequest;
use futures_old_for_limiter::Future;
use http_server_common::request::get_request_ip::get_request_ip;
@@ -1,4 +1,4 @@
use actix_http::http::header;
use actix_http::header::CONTENT_TYPE;
use actix_web::HttpResponseBuilder;
use actix_web::http::StatusCode;
use actix_web::{HttpResponse, ResponseError};
@@ -25,6 +25,6 @@ pub fn to_simple_json_error(
};
HttpResponseBuilder::new(status_code)
.set_header(header::CONTENT_TYPE, "application/json")
.set_header(CONTENT_TYPE, "application/json")
.body(body)
}
Loaded 100 of 105 files, more files were not shown because too many files have changed in this diff. Show more