Upgrade http crate (#5006)

* Remove opentelemetry

* remove unused deps, use backtrace

* always print db migration messages regardless of log level (fixes #4725)

* fix ci

* Remove useless root span builder

* Upgrade http and opentelemetry crates

* more fixes

* cleanup

* use release

* upgrade more deps
This commit is contained in:
Nutomic 2024-09-12 11:49:09 +02:00 committed by GitHub
parent a6220537b5
commit dea6ee462c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 658 additions and 447 deletions

1035
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -91,7 +91,7 @@ lemmy_db_views = { version = "=0.19.6-beta.7", path = "./crates/db_views" }
lemmy_db_views_actor = { version = "=0.19.6-beta.7", path = "./crates/db_views_actor" } lemmy_db_views_actor = { version = "=0.19.6-beta.7", path = "./crates/db_views_actor" }
lemmy_db_views_moderator = { version = "=0.19.6-beta.7", path = "./crates/db_views_moderator" } lemmy_db_views_moderator = { version = "=0.19.6-beta.7", path = "./crates/db_views_moderator" }
lemmy_federate = { version = "=0.19.6-beta.7", path = "./crates/federate" } lemmy_federate = { version = "=0.19.6-beta.7", path = "./crates/federate" }
activitypub_federation = { version = "0.5.8", default-features = false, features = [ activitypub_federation = { version = "0.6.0-alpha1", default-features = false, features = [
"actix-web", "actix-web",
] } ] }
diesel = "2.1.6" diesel = "2.1.6"
@ -99,7 +99,7 @@ diesel_migrations = "2.1.0"
diesel-async = "0.4.1" diesel-async = "0.4.1"
serde = { version = "1.0.204", features = ["derive"] } serde = { version = "1.0.204", features = ["derive"] }
serde_with = "3.9.0" serde_with = "3.9.0"
actix-web = { version = "4.8.0", default-features = false, features = [ actix-web = { version = "4.9.0", default-features = false, features = [
"macros", "macros",
"rustls-0_23", "rustls-0_23",
"compress-brotli", "compress-brotli",
@ -111,14 +111,14 @@ tracing = "0.1.40"
tracing-actix-web = { version = "0.7.10", default-features = false } tracing-actix-web = { version = "0.7.10", default-features = false }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
url = { version = "2.5.2", features = ["serde"] } url = { version = "2.5.2", features = ["serde"] }
reqwest = { version = "0.11.27", default-features = false, features = [ reqwest = { version = "0.12.7", default-features = false, features = [
"json", "json",
"blocking", "blocking",
"gzip", "gzip",
"rustls-tls", "rustls-tls",
] } ] }
reqwest-middleware = "0.2.5" reqwest-middleware = "0.3.3"
reqwest-tracing = "0.4.8" reqwest-tracing = "0.5.3"
clokwerk = "0.4.0" clokwerk = "0.4.0"
doku = { version = "0.21.1", features = ["url-2"] } doku = { version = "0.21.1", features = ["url-2"] }
bcrypt = "0.15.1" bcrypt = "0.15.1"
@ -141,7 +141,7 @@ diesel-derive-enum = { version = "2.1.0", features = ["postgres"] }
strum = { version = "0.26.3", features = ["derive"] } strum = { version = "0.26.3", features = ["derive"] }
itertools = "0.13.0" itertools = "0.13.0"
futures = "0.3.30" futures = "0.3.30"
http = "0.2.12" http = "1.1"
rosetta-i18n = "0.1.3" rosetta-i18n = "0.1.3"
ts-rs = { version = "7.1.1", features = [ ts-rs = { version = "7.1.1", features = [
"serde-compat", "serde-compat",

View File

@ -11,7 +11,6 @@ use activitypub_federation::{
FEDERATION_CONTENT_TYPE, FEDERATION_CONTENT_TYPE,
}; };
use actix_web::{web, web::Bytes, HttpRequest, HttpResponse}; use actix_web::{web, web::Bytes, HttpRequest, HttpResponse};
use http::{header::LOCATION, StatusCode};
use lemmy_api_common::context::LemmyContext; use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::DbUrl, newtypes::DbUrl,
@ -76,14 +75,14 @@ fn create_apub_tombstone_response<T: Into<Url>>(id: T) -> LemmyResult<HttpRespon
Ok( Ok(
HttpResponse::Gone() HttpResponse::Gone()
.content_type(FEDERATION_CONTENT_TYPE) .content_type(FEDERATION_CONTENT_TYPE)
.status(StatusCode::GONE) .status(actix_web::http::StatusCode::GONE)
.body(json), .body(json),
) )
} }
fn redirect_remote_object(url: &DbUrl) -> HttpResponse { fn redirect_remote_object(url: &DbUrl) -> HttpResponse {
let mut res = HttpResponse::PermanentRedirect(); let mut res = HttpResponse::PermanentRedirect();
res.insert_header((LOCATION, url.as_str())); res.insert_header((actix_web::http::header::LOCATION, url.as_str()));
res.finish() res.finish()
} }

View File

@ -32,7 +32,7 @@ serde_json.workspace = true
tokio = { workspace = true, features = ["full"] } tokio = { workspace = true, features = ["full"] }
tracing.workspace = true tracing.workspace = true
moka.workspace = true moka.workspace = true
tokio-util = "0.7.11" tokio-util = "0.7.12"
async-trait.workspace = true async-trait.workspace = true
[dev-dependencies] [dev-dependencies]

View File

@ -459,7 +459,6 @@ mod test {
traits::Crud, traits::Crud,
}; };
use lemmy_utils::error::LemmyResult; use lemmy_utils::error::LemmyResult;
use reqwest::StatusCode;
use serde_json::{json, Value}; use serde_json::{json, Value};
use serial_test::serial; use serial_test::serial;
use test_context::{test_context, AsyncTestContext}; use test_context::{test_context, AsyncTestContext};
@ -688,7 +687,7 @@ mod test {
|inbox_sender: actix_web::web::Data<UnboundedSender<String>>, body: String| async move { |inbox_sender: actix_web::web::Data<UnboundedSender<String>>, body: String| async move {
tracing::debug!("received activity: {:?}", body); tracing::debug!("received activity: {:?}", body);
inbox_sender.send(body.clone()).unwrap(); inbox_sender.send(body.clone()).unwrap();
HttpResponse::new(StatusCode::OK) HttpResponse::new(actix_web::http::StatusCode::OK)
}, },
), ),
) )

View File

@ -32,4 +32,5 @@ serde = { workspace = true }
url = { workspace = true } url = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
tokio = { workspace = true } tokio = { workspace = true }
rss = "2.0.8" http.workspace = true
rss = "2.0.9"

View File

@ -2,6 +2,7 @@ use actix_web::{
body::BodyStream, body::BodyStream,
http::{ http::{
header::{HeaderName, ACCEPT_ENCODING, HOST}, header::{HeaderName, ACCEPT_ENCODING, HOST},
Method,
StatusCode, StatusCode,
}, },
web, web,
@ -10,6 +11,7 @@ use actix_web::{
HttpResponse, HttpResponse,
}; };
use futures::stream::{Stream, StreamExt}; use futures::stream::{Stream, StreamExt};
use http::HeaderValue;
use lemmy_api_common::{context::LemmyContext, request::PictrsResponse}; use lemmy_api_common::{context::LemmyContext, request::PictrsResponse};
use lemmy_db_schema::source::{ use lemmy_db_schema::source::{
images::{LocalImage, LocalImageForm, RemoteImage}, images::{LocalImage, LocalImageForm, RemoteImage},
@ -109,7 +111,7 @@ fn adapt_request(
const INVALID_HEADERS: &[HeaderName] = &[ACCEPT_ENCODING, HOST]; const INVALID_HEADERS: &[HeaderName] = &[ACCEPT_ENCODING, HOST];
let client_request = client let client_request = client
.request(request.method().clone(), url) .request(convert_method(request.method()), url)
.timeout(REQWEST_TIMEOUT); .timeout(REQWEST_TIMEOUT);
request request
@ -119,7 +121,8 @@ fn adapt_request(
if INVALID_HEADERS.contains(key) { if INVALID_HEADERS.contains(key) {
client_req client_req
} else { } else {
client_req.header(key, value) // TODO: remove as_str and as_bytes conversions after actix-web upgrades to http 1.0
client_req.header(key.as_str(), value.as_bytes())
} }
}) })
} }
@ -166,7 +169,7 @@ async fn upload(
} }
} }
Ok(HttpResponse::build(status).json(images)) Ok(HttpResponse::build(convert_status(status)).json(images))
} }
async fn full_res( async fn full_res(
@ -209,14 +212,14 @@ async fn image(
let res = client_req.send().await?; let res = client_req.send().await?;
if res.status() == StatusCode::NOT_FOUND { if res.status() == http::StatusCode::NOT_FOUND {
return Ok(HttpResponse::NotFound().finish()); return Ok(HttpResponse::NotFound().finish());
} }
let mut client_res = HttpResponse::build(res.status()); let mut client_res = HttpResponse::build(StatusCode::from_u16(res.status().as_u16())?);
for (name, value) in res.headers().iter().filter(|(h, _)| *h != "connection") { for (name, value) in res.headers().iter().filter(|(h, _)| *h != "connection") {
client_res.insert_header((name.clone(), value.clone())); client_res.insert_header(convert_header(name, value));
} }
Ok(client_res.body(BodyStream::new(res.bytes_stream()))) Ok(client_res.body(BodyStream::new(res.bytes_stream())))
@ -245,7 +248,7 @@ async fn delete(
LocalImage::delete_by_alias(&mut context.pool(), &file).await?; LocalImage::delete_by_alias(&mut context.pool(), &file).await?;
Ok(HttpResponse::build(res.status()).body(BodyStream::new(res.bytes_stream()))) Ok(HttpResponse::build(convert_status(res.status())).body(BodyStream::new(res.bytes_stream())))
} }
pub async fn image_proxy( pub async fn image_proxy(
@ -308,3 +311,14 @@ where
std::pin::Pin::new(&mut self.rx).poll_recv(cx) std::pin::Pin::new(&mut self.rx).poll_recv(cx)
} }
} }
// TODO: remove these conversions after actix-web upgrades to http 1.0
fn convert_status(status: http::StatusCode) -> StatusCode {
StatusCode::from_u16(status.as_u16()).expect("status can be converted")
}
fn convert_method(method: &Method) -> http::Method {
http::Method::from_bytes(method.as_str().as_bytes()).expect("method can be converted")
}
fn convert_header<'a>(name: &'a http::HeaderName, value: &'a HeaderValue) -> (&'a str, &'a [u8]) {
(name.as_str(), value.as_bytes())
}

View File

@ -84,7 +84,7 @@ async fn get_webfinger_response(
Ok( Ok(
HttpResponse::Ok() HttpResponse::Ok()
.content_type(&WEBFINGER_CONTENT_TYPE) .content_type(WEBFINGER_CONTENT_TYPE.as_bytes())
.json(json), .json(json),
) )
} }

View File

@ -71,7 +71,7 @@ urlencoding = { workspace = true, optional = true }
html2text = { version = "0.12.5", optional = true } html2text = { version = "0.12.5", optional = true }
deser-hjson = { version = "2.2.4", optional = true } deser-hjson = { version = "2.2.4", optional = true }
smart-default = { version = "0.7.1", optional = true } smart-default = { version = "0.7.1", optional = true }
lettre = { version = "0.11.7", default-features = false, features = [ lettre = { version = "0.11.8", default-features = false, features = [
"builder", "builder",
"tokio1", "tokio1",
"tokio1-rustls-tls", "tokio1-rustls-tls",

View File

@ -231,13 +231,13 @@ cfg_if! {
} }
impl actix_web::error::ResponseError for LemmyError { impl actix_web::error::ResponseError for LemmyError {
fn status_code(&self) -> http::StatusCode { fn status_code(&self) -> actix_web::http::StatusCode {
if self.error_type == LemmyErrorType::IncorrectLogin { if self.error_type == LemmyErrorType::IncorrectLogin {
return http::StatusCode::UNAUTHORIZED; return actix_web::http::StatusCode::UNAUTHORIZED;
} }
match self.inner.downcast_ref::<diesel::result::Error>() { match self.inner.downcast_ref::<diesel::result::Error>() {
Some(diesel::result::Error::NotFound) => http::StatusCode::NOT_FOUND, Some(diesel::result::Error::NotFound) => actix_web::http::StatusCode::NOT_FOUND,
_ => http::StatusCode::BAD_REQUEST, _ => actix_web::http::StatusCode::BAD_REQUEST,
} }
} }

View File

@ -37,6 +37,7 @@ mod tests {
use crate::error::{LemmyError, LemmyErrorType}; use crate::error::{LemmyError, LemmyErrorType};
use actix_web::{ use actix_web::{
error::ErrorInternalServerError, error::ErrorInternalServerError,
http::StatusCode,
middleware::ErrorHandlers, middleware::ErrorHandlers,
test, test,
web, web,
@ -45,7 +46,6 @@ mod tests {
Handler, Handler,
Responder, Responder,
}; };
use http::StatusCode;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
#[actix_web::test] #[actix_web::test]

View File

@ -1,7 +1,7 @@
use actix_web::{ use actix_web::{
body::MessageBody, body::MessageBody,
dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform}, dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform},
http::header::CACHE_CONTROL, http::header::{HeaderValue, CACHE_CONTROL},
Error, Error,
HttpMessage, HttpMessage,
}; };
@ -9,7 +9,6 @@ use core::future::Ready;
use futures_util::future::LocalBoxFuture; use futures_util::future::LocalBoxFuture;
use lemmy_api::{local_user_view_from_jwt, read_auth_token}; use lemmy_api::{local_user_view_from_jwt, read_auth_token};
use lemmy_api_common::context::LemmyContext; use lemmy_api_common::context::LemmyContext;
use reqwest::header::HeaderValue;
use std::{future::ready, rc::Rc}; use std::{future::ready, rc::Rc};
#[derive(Clone)] #[derive(Clone)]