refactor: drop dead code in the media proxy and push

This commit is contained in:
Hampus committed 2026-11-27 14:48:55 +01:00
1 parent f3f0859b56
commit 03fc50fa46
17 files changed
-73

No files matched your search

@@ -99,10 +99,6 @@ impl Default for HTTPClientOptions {
}
pub fn build_raw(options: HTTPClientOptions) -> Result<reqwest::Client, reqwest::Error> {
// System proxy discovery stays on. HTTP_PROXY, HTTPS_PROXY, ALL_PROXY and NO_PROXY are part
// of the deployment's egress configuration, so an operator who funnels egress through a
// gateway gets storage reads and external fetches routed through it. The healthcheck probe
// is the one client that opts out, because it only ever dials this process on loopback.
let mut builder = reqwest::Client::builder()
.connect_timeout(Duration::from_millis(options.connect_timeout_ms.get()))
.redirect(reqwest::redirect::Policy::none())
@@ -93,8 +93,6 @@ fn retryable_status(status: StatusCode) -> Option<Retryable> {
}
fn retryable_error(error: &MiddlewareError) -> Option<Retryable> {
// A pinned-resolver rejection is a policy decision, not a transient fault, and retrying it only
// repeats the same lookup against a name the caller supplied.
if crate::public_net_policy::is_pinned_dns_failure(error) {
return Some(Retryable::Fatal);
}
@@ -461,8 +461,6 @@ pub(super) fn encode_animated_apng(
let mut sequence_number = 0u32;
let mut encoded_frames = 0usize;
for frame_index in 0..frame_count {
// Overrunning the encode deadline shortens the animation instead of failing the request;
// the flush headroom is reserved so the frames already written still reach the client.
if ensure_deadline_pending(deadline).is_err() {
break;
}
@@ -40,7 +40,6 @@ impl NSFWFrameOutput {
.try_reserve_exact(self.expected)
.map_err(|_| NSFWFrameCopyError::AllocationFailed)?;
for slot in self.slots.iter().take(self.expected) {
// a sample the native decoder could not reach leaves its slot empty
let Some(data) = NonNull::new(slot.data.cast::<u8>()) else {
if slot.len != 0 {
return Err(NSFWFrameCopyError::InvalidOutput);
@@ -228,8 +228,6 @@ int fluxer_read_gif_frame_delays(const uint8_t *bytes, size_t len,
}
int status = skip_gif_image_block(bytes, len, &offset, &block_count);
if (status != FLUXER_NATIVE_STATUS_OK) return status;
/* A frame with no Graphics Control Extension declares no delay, which renders at the
* 100 ms browser default rather than the fast-frame minimum. */
int delay_cs = has_pending_delay
? pending_delay_cs
: FLUXER_DEFAULT_ANIMATION_FRAME_DELAY_MS / 10;
@@ -957,9 +957,6 @@ static int fluxer_nsfw_decode_targets(
continue;
}
if (fluxer_nsfw_sample_failure_fatal(status)) return status;
/* A sample the decoder cannot reach falls back to the last frame it did
decode, and otherwise leaves its slot empty, so the samples that did
decode still reach the classifier. */
if (group.next < limit && outputs[group.next].data == NULL) {
(void)fluxer_nsfw_emit_candidate(&group);
}
@@ -54,8 +54,6 @@ impl Resolve for PinnedDnsResolver {
}
}
// reqwest and the hyper connector box this rejection behind errors of their own, so the source
// chain is the only way back to the decision the resolver made.
pub fn is_pinned_dns_failure(error: &(dyn std::error::Error + 'static)) -> bool {
let mut current = Some(error);
while let Some(error) = current {
@@ -42,8 +42,6 @@ impl DownloadStreamPolicy {
}
}
// Only the external route feeds the overrun counter: a stored object that outruns its own
// Content-Length is a store bug, not the misbehaving-origin signal that series tracks.
pub(in crate::server) fn for_external(
socket_io_timeout_ms: NonZeroU64,
overruns: Arc<ExternalMetrics>,
-5
View File
@@ -54,8 +54,6 @@ const EXTERNAL_HINT_CACHE_ENTRIES: u64 = 4096;
pub(in crate::server) type ExternalHintCache = moka::sync::Cache<String, ExternalHint>;
// What the origin last served for a url, so a repeat transform of a hot embed can be
// answered from the transform cache instead of downloading the origin asset again.
#[derive(Clone)]
pub(in crate::server) struct ExternalHint {
url: String,
@@ -303,9 +301,6 @@ pub(in crate::server) async fn serve_external(
serve_fetched_external(prepared, fetched).await
}
// Unlike the object store, a third-party origin answers a GET by sending a body the proxy
// then discards, and an untrusted content type makes the proxy buffer that body in full.
// A metadata-only probe is worth its own upstream HEAD here.
async fn external_head_passthrough(
app: &AppState,
url: &str,
-2
View File
@@ -23,8 +23,6 @@ pub(super) enum ExternalStreamDecision {
Buffer,
}
// A passthrough streams on the strength of its content type alone. An upstream that declares no
// length still streams; the declared length only decides whether the response can name one.
pub(super) fn external_stream_decision(
allow_stream: bool,
content_length: Option<u64>,
@@ -513,15 +513,6 @@ mod tests {
segment
}
fn authorized_headers() -> HeaderMap {
let mut headers = HeaderMap::new();
headers.insert(
header::AUTHORIZATION,
HeaderValue::from_static("Bearer secret"),
);
headers
}
fn json_request(body: String) -> Request<Body> {
Request::builder()
.method(Method::POST)
@@ -539,13 +530,6 @@ mod tests {
String::from_utf8(bytes.to_vec()).expect("utf8 body")
}
#[test]
fn internal_auth_uses_bearer_secret() {
let headers = authorized_headers();
assert!(check_internal_auth(&headers, "secret"));
assert!(!check_internal_auth(&headers, "other"));
}
#[tokio::test]
async fn sniff_requires_the_internal_bearer_secret() {
let (_tmp, app) = local_storage_app();
@@ -263,8 +263,6 @@ fn svg_rasterize_failed_response(cache_identity: &str) -> Response {
)
}
/// Resolves the object's full length, preferring what the store already reported on the streamed
/// reply so the common path never needs a second upstream request.
async fn passthrough_total_len(
app: &Arc<AppState>,
bucket: &str,
@@ -53,9 +53,6 @@ pub(super) fn streaming_media_response(response: StreamingMediaResponse<'_>) ->
} else {
StatusCode::OK
};
// Advertise the range the store actually satisfied, not one recomputed locally: an origin is
// free to answer a different span than the client asked for, and Content-Range must describe
// the bytes in this body.
let effective_byte_range = if status == StatusCode::PARTIAL_CONTENT {
object.byte_range
} else {
@@ -141,10 +141,6 @@ pub(in crate::server) fn coalesced_work_result<T>(result: anyhow::Result<T>) ->
}
pub(in crate::server) fn transform_error_is_timeout(error: &anyhow::Error) -> bool {
// A shed admission is reported as a timeout: the old era had one admission semaphore whose
// exhaustion surfaced as TimedSemaphoreError::RequestTimeout, so every caller answered 504
// with its own timeout reason code. Giving a full queue its own class moves the transform
// routes to 503 and metadata SVG rasterize to 400.
let admission = error.downcast_ref::<TimedSemaphoreError>();
error.downcast_ref::<MediaError>() == Some(&MediaError::RequestTimeout)
|| admission == Some(&TimedSemaphoreError::RequestTimeout)
@@ -748,8 +748,6 @@ pub(in crate::server) struct CachedTransformProbe<'a> {
pub(in crate::server) params: &'a HashMap<String, String>,
}
// Answers a repeat transform from the cache without the caller fetching the source
// bytes again, so a hot remote asset costs one upstream fetch per cache lifetime.
pub(in crate::server) fn cached_transform_response(
runtime: &TransformRuntime,
probe: CachedTransformProbe<'_>,
-3
View File
@@ -79,9 +79,6 @@ impl Store {
bucket: &str,
key: &str,
) -> Result<HeadResult, StorageError> {
// A HEAD is a read, so it follows the same endpoint and signing policy as a body read.
// Sending it to the write origin instead would bypass the configured read endpoint and
// attach credentials to a read the operator configured as unsigned.
let url = self.s3_read_url(bucket, key)?;
let headers = self.read_headers(bucket, Method::HEAD, &url, &[])?;
let response = self.client.head(&url).headers(headers).send().await?;
-18
View File
@@ -757,24 +757,6 @@ mod tests {
RelayConfig::load_from_iter(extra.iter().copied())
}
#[test]
fn metrics_port_is_off_when_unset() {
assert_eq!(None, delivery(&[]).expect("config").metrics_port);
assert_eq!(
None,
delivery(&[("FLUXER_PUSH_METRICS_PORT", " ")])
.expect("config")
.metrics_port
);
}
#[test]
fn metrics_port_is_read_in_both_modes() {
let extra = [("FLUXER_PUSH_METRICS_PORT", "8082")];
assert_eq!(Some(8082), delivery(&extra).expect("config").metrics_port);
assert_eq!(Some(8082), relay(&extra).expect("config").metrics_port);
}
#[test]
fn metrics_port_must_be_nonzero_and_differ_from_the_service_port() {
for port in ["0", "8126", "not-a-port", "70000"] {