This commit is contained in:
Tangel 2024-03-05 05:35:06 +00:00 committed by GitHub
parent 3a80357325
commit f05bb726f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 14 deletions

View file

@ -423,6 +423,7 @@ mod tests {
use bytes::Bytes; use bytes::Bytes;
use http::{HeaderMap, StatusCode}; use http::{HeaderMap, StatusCode};
use std::time::Instant; use std::time::Instant;
use tokio::net::TcpListener;
use tracing::debug; use tracing::debug;
// This will periodically send back internal errors to test the retry // This will periodically send back internal errors to test the retry
@ -450,8 +451,10 @@ mod tests {
.route("/", post(dodgy_handler)) .route("/", post(dodgy_handler))
.with_state(state); .with_state(state);
axum::Server::bind(&"0.0.0.0:8002".parse().unwrap()) axum::serve(
.serve(app.into_make_service()) TcpListener::bind("0.0.0.0:8002").await.unwrap(),
app.into_make_service(),
)
.await .await
.unwrap(); .unwrap();
} }

View file

@ -214,6 +214,7 @@ pub(crate) fn generate_request_headers(inbox_url: &Url) -> HeaderMap {
mod tests { mod tests {
use super::*; use super::*;
use crate::{config::FederationConfig, http_signatures::generate_actor_keypair}; use crate::{config::FederationConfig, http_signatures::generate_actor_keypair};
use axum::extract::State;
use bytes::Bytes; use bytes::Bytes;
use http::StatusCode; use http::StatusCode;
use std::{ use std::{

View file

@ -64,20 +64,18 @@ where
{ {
type Rejection = Response; type Rejection = Response;
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> { async fn from_request(req: Request, _state: &S) -> Result<Self, Self::Rejection> {
let headers = req.headers().clone(); let (parts, body) = req.into_parts();
let method = req.method().clone();
let uri = req.uri().clone();
// this wont work if the body is an long running stream // 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 .await
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response())?; .map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response())?;
Ok(Self { Ok(Self {
headers, headers: parts.headers,
method, method: parts.method,
uri, uri: parts.uri,
body: bytes.to_vec(), body: bytes.to_vec(),
}) })
} }

View file

@ -94,7 +94,7 @@ async fn fetch_object_http_with_accept<T: Clone, Kind: DeserializeOwned>(
let req = config let req = config
.client .client
.get(url.as_str()) .get(url.as_str())
.header("Accept", content_type) .header("Accept", content_type.as_bytes())
.timeout(config.request_timeout); .timeout(config.request_timeout);
let res = if let Some((actor_id, private_key_pem)) = config.signed_fetch_actor.as_deref() { 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 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 text = res.bytes_limited().await?;
let object_id = extract_id(&text).ok(); let object_id = extract_id(&text).ok();