mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-10 06:54:12 +00:00
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:
parent
a6220537b5
commit
dea6ee462c
12 changed files with 658 additions and 447 deletions
1035
Cargo.lock
generated
1035
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
12
Cargo.toml
12
Cargo.toml
|
@ -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_moderator = { version = "=0.19.6-beta.7", path = "./crates/db_views_moderator" }
|
||||
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",
|
||||
] }
|
||||
diesel = "2.1.6"
|
||||
|
@ -99,7 +99,7 @@ diesel_migrations = "2.1.0"
|
|||
diesel-async = "0.4.1"
|
||||
serde = { version = "1.0.204", features = ["derive"] }
|
||||
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",
|
||||
"rustls-0_23",
|
||||
"compress-brotli",
|
||||
|
@ -111,14 +111,14 @@ tracing = "0.1.40"
|
|||
tracing-actix-web = { version = "0.7.10", default-features = false }
|
||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||
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",
|
||||
"blocking",
|
||||
"gzip",
|
||||
"rustls-tls",
|
||||
] }
|
||||
reqwest-middleware = "0.2.5"
|
||||
reqwest-tracing = "0.4.8"
|
||||
reqwest-middleware = "0.3.3"
|
||||
reqwest-tracing = "0.5.3"
|
||||
clokwerk = "0.4.0"
|
||||
doku = { version = "0.21.1", features = ["url-2"] }
|
||||
bcrypt = "0.15.1"
|
||||
|
@ -141,7 +141,7 @@ diesel-derive-enum = { version = "2.1.0", features = ["postgres"] }
|
|||
strum = { version = "0.26.3", features = ["derive"] }
|
||||
itertools = "0.13.0"
|
||||
futures = "0.3.30"
|
||||
http = "0.2.12"
|
||||
http = "1.1"
|
||||
rosetta-i18n = "0.1.3"
|
||||
ts-rs = { version = "7.1.1", features = [
|
||||
"serde-compat",
|
||||
|
|
|
@ -11,7 +11,6 @@ use activitypub_federation::{
|
|||
FEDERATION_CONTENT_TYPE,
|
||||
};
|
||||
use actix_web::{web, web::Bytes, HttpRequest, HttpResponse};
|
||||
use http::{header::LOCATION, StatusCode};
|
||||
use lemmy_api_common::context::LemmyContext;
|
||||
use lemmy_db_schema::{
|
||||
newtypes::DbUrl,
|
||||
|
@ -76,14 +75,14 @@ fn create_apub_tombstone_response<T: Into<Url>>(id: T) -> LemmyResult<HttpRespon
|
|||
Ok(
|
||||
HttpResponse::Gone()
|
||||
.content_type(FEDERATION_CONTENT_TYPE)
|
||||
.status(StatusCode::GONE)
|
||||
.status(actix_web::http::StatusCode::GONE)
|
||||
.body(json),
|
||||
)
|
||||
}
|
||||
|
||||
fn redirect_remote_object(url: &DbUrl) -> HttpResponse {
|
||||
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()
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ serde_json.workspace = true
|
|||
tokio = { workspace = true, features = ["full"] }
|
||||
tracing.workspace = true
|
||||
moka.workspace = true
|
||||
tokio-util = "0.7.11"
|
||||
tokio-util = "0.7.12"
|
||||
async-trait.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -459,7 +459,6 @@ mod test {
|
|||
traits::Crud,
|
||||
};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
use reqwest::StatusCode;
|
||||
use serde_json::{json, Value};
|
||||
use serial_test::serial;
|
||||
use test_context::{test_context, AsyncTestContext};
|
||||
|
@ -688,7 +687,7 @@ mod test {
|
|||
|inbox_sender: actix_web::web::Data<UnboundedSender<String>>, body: String| async move {
|
||||
tracing::debug!("received activity: {:?}", body);
|
||||
inbox_sender.send(body.clone()).unwrap();
|
||||
HttpResponse::new(StatusCode::OK)
|
||||
HttpResponse::new(actix_web::http::StatusCode::OK)
|
||||
},
|
||||
),
|
||||
)
|
||||
|
|
|
@ -32,4 +32,5 @@ serde = { workspace = true }
|
|||
url = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
rss = "2.0.8"
|
||||
http.workspace = true
|
||||
rss = "2.0.9"
|
||||
|
|
|
@ -2,6 +2,7 @@ use actix_web::{
|
|||
body::BodyStream,
|
||||
http::{
|
||||
header::{HeaderName, ACCEPT_ENCODING, HOST},
|
||||
Method,
|
||||
StatusCode,
|
||||
},
|
||||
web,
|
||||
|
@ -10,6 +11,7 @@ use actix_web::{
|
|||
HttpResponse,
|
||||
};
|
||||
use futures::stream::{Stream, StreamExt};
|
||||
use http::HeaderValue;
|
||||
use lemmy_api_common::{context::LemmyContext, request::PictrsResponse};
|
||||
use lemmy_db_schema::source::{
|
||||
images::{LocalImage, LocalImageForm, RemoteImage},
|
||||
|
@ -109,7 +111,7 @@ fn adapt_request(
|
|||
const INVALID_HEADERS: &[HeaderName] = &[ACCEPT_ENCODING, HOST];
|
||||
|
||||
let client_request = client
|
||||
.request(request.method().clone(), url)
|
||||
.request(convert_method(request.method()), url)
|
||||
.timeout(REQWEST_TIMEOUT);
|
||||
|
||||
request
|
||||
|
@ -119,7 +121,8 @@ fn adapt_request(
|
|||
if INVALID_HEADERS.contains(key) {
|
||||
client_req
|
||||
} 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(
|
||||
|
@ -209,14 +212,14 @@ async fn image(
|
|||
|
||||
let res = client_req.send().await?;
|
||||
|
||||
if res.status() == StatusCode::NOT_FOUND {
|
||||
if res.status() == http::StatusCode::NOT_FOUND {
|
||||
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") {
|
||||
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())))
|
||||
|
@ -245,7 +248,7 @@ async fn delete(
|
|||
|
||||
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(
|
||||
|
@ -308,3 +311,14 @@ where
|
|||
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())
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ async fn get_webfinger_response(
|
|||
|
||||
Ok(
|
||||
HttpResponse::Ok()
|
||||
.content_type(&WEBFINGER_CONTENT_TYPE)
|
||||
.content_type(WEBFINGER_CONTENT_TYPE.as_bytes())
|
||||
.json(json),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ urlencoding = { workspace = true, optional = true }
|
|||
html2text = { version = "0.12.5", optional = true }
|
||||
deser-hjson = { version = "2.2.4", 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",
|
||||
"tokio1",
|
||||
"tokio1-rustls-tls",
|
||||
|
|
|
@ -231,13 +231,13 @@ cfg_if! {
|
|||
}
|
||||
|
||||
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 {
|
||||
return http::StatusCode::UNAUTHORIZED;
|
||||
return actix_web::http::StatusCode::UNAUTHORIZED;
|
||||
}
|
||||
match self.inner.downcast_ref::<diesel::result::Error>() {
|
||||
Some(diesel::result::Error::NotFound) => http::StatusCode::NOT_FOUND,
|
||||
_ => http::StatusCode::BAD_REQUEST,
|
||||
Some(diesel::result::Error::NotFound) => actix_web::http::StatusCode::NOT_FOUND,
|
||||
_ => actix_web::http::StatusCode::BAD_REQUEST,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ mod tests {
|
|||
use crate::error::{LemmyError, LemmyErrorType};
|
||||
use actix_web::{
|
||||
error::ErrorInternalServerError,
|
||||
http::StatusCode,
|
||||
middleware::ErrorHandlers,
|
||||
test,
|
||||
web,
|
||||
|
@ -45,7 +46,6 @@ mod tests {
|
|||
Handler,
|
||||
Responder,
|
||||
};
|
||||
use http::StatusCode;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[actix_web::test]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use actix_web::{
|
||||
body::MessageBody,
|
||||
dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform},
|
||||
http::header::CACHE_CONTROL,
|
||||
http::header::{HeaderValue, CACHE_CONTROL},
|
||||
Error,
|
||||
HttpMessage,
|
||||
};
|
||||
|
@ -9,7 +9,6 @@ use core::future::Ready;
|
|||
use futures_util::future::LocalBoxFuture;
|
||||
use lemmy_api::{local_user_view_from_jwt, read_auth_token};
|
||||
use lemmy_api_common::context::LemmyContext;
|
||||
use reqwest::header::HeaderValue;
|
||||
use std::{future::ready, rc::Rc};
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
Loading…
Reference in a new issue