mirror of
https://github.com/LemmyNet/activitypub-federation-rust.git
synced 2024-05-19 09:28:04 +00:00
update
This commit is contained in:
parent
3a80357325
commit
f05bb726f2
|
@ -423,6 +423,7 @@ mod tests {
|
|||
use bytes::Bytes;
|
||||
use http::{HeaderMap, StatusCode};
|
||||
use std::time::Instant;
|
||||
use tokio::net::TcpListener;
|
||||
use tracing::debug;
|
||||
|
||||
// This will periodically send back internal errors to test the retry
|
||||
|
@ -450,10 +451,12 @@ mod tests {
|
|||
.route("/", post(dodgy_handler))
|
||||
.with_state(state);
|
||||
|
||||
axum::Server::bind(&"0.0.0.0:8002".parse().unwrap())
|
||||
.serve(app.into_make_service())
|
||||
.await
|
||||
.unwrap();
|
||||
axum::serve(
|
||||
TcpListener::bind("0.0.0.0:8002").await.unwrap(),
|
||||
app.into_make_service(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
|
|
|
@ -214,6 +214,7 @@ pub(crate) fn generate_request_headers(inbox_url: &Url) -> HeaderMap {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use crate::{config::FederationConfig, http_signatures::generate_actor_keypair};
|
||||
use axum::extract::State;
|
||||
use bytes::Bytes;
|
||||
use http::StatusCode;
|
||||
use std::{
|
||||
|
|
|
@ -64,20 +64,18 @@ where
|
|||
{
|
||||
type Rejection = Response;
|
||||
|
||||
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> {
|
||||
let headers = req.headers().clone();
|
||||
let method = req.method().clone();
|
||||
let uri = req.uri().clone();
|
||||
async fn from_request(req: Request, _state: &S) -> Result<Self, Self::Rejection> {
|
||||
let (parts, body) = req.into_parts();
|
||||
|
||||
// this wont work if the body is an long running stream
|
||||
let bytes = hyper::body::Bytes::from_request(req, state)
|
||||
let bytes = axum::body::to_bytes(body, usize::MAX)
|
||||
.await
|
||||
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response())?;
|
||||
|
||||
Ok(Self {
|
||||
headers,
|
||||
method,
|
||||
uri,
|
||||
headers: parts.headers,
|
||||
method: parts.method,
|
||||
uri: parts.uri,
|
||||
body: bytes.to_vec(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ async fn fetch_object_http_with_accept<T: Clone, Kind: DeserializeOwned>(
|
|||
let req = config
|
||||
.client
|
||||
.get(url.as_str())
|
||||
.header("Accept", content_type)
|
||||
.header("Accept", content_type.as_bytes())
|
||||
.timeout(config.request_timeout);
|
||||
|
||||
let res = if let Some((actor_id, private_key_pem)) = config.signed_fetch_actor.as_deref() {
|
||||
|
@ -116,7 +116,11 @@ async fn fetch_object_http_with_accept<T: Clone, Kind: DeserializeOwned>(
|
|||
}
|
||||
|
||||
let url = res.url().clone();
|
||||
let content_type = res.headers().get("Content-Type").cloned();
|
||||
let content_type = res
|
||||
.headers()
|
||||
.get("Content-Type")
|
||||
.cloned()
|
||||
.and_then(|v| HeaderValue::from_maybe_shared(v).ok());
|
||||
let text = res.bytes_limited().await?;
|
||||
let object_id = extract_id(&text).ok();
|
||||
|
||||
|
|
Loading…
Reference in a new issue