Skip to content

Commit c3acdfa

Browse files
committed
chore: fixed proxying of media
1 parent 35352a8 commit c3acdfa

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/client.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::result::Result;
1414
use std::sync::atomic::Ordering;
1515
use std::sync::atomic::{AtomicBool, AtomicU16};
1616
use std::sync::LazyLock;
17+
use wreq::redirect::Policy;
1718
use wreq::{header as wreq_header, Client as WreqClient, EmulationFactory, Method, Response as WreqResponse};
1819
use wreq_util::{Emulation, EmulationOS, EmulationOption};
1920

@@ -58,7 +59,11 @@ pub fn build_client() -> WreqClient {
5859
.emulation();
5960

6061
info!("Building Wreq client with random emulation {:?}", emulation);
61-
WreqClient::builder().emulation(emulation).build().expect("Should always be able to build a client")
62+
WreqClient::builder()
63+
.emulation(emulation)
64+
.redirect(Policy::none())
65+
.build()
66+
.expect("Should always be able to build a client")
6267
}
6368

6469
/// Gets the canonical path for a resource on Reddit. This is accomplished by
@@ -175,6 +180,9 @@ pub async fn proxy(req: HyperRequest<Body>, format: &str) -> Result<HyperRespons
175180
builder = builder.header("User-Agent", client.user_agent());
176181
}
177182

183+
// This is needed or Reddit will redirect us to a /media landing page that just renders the image.
184+
builder = builder.header(wreq_header::ACCEPT, "*/*");
185+
178186
builder
179187
.send()
180188
.await

0 commit comments

Comments
 (0)