Skip to content

Commit

Permalink
Revert "remove content_type from endpoint config"
Browse files Browse the repository at this point in the history
This reverts commit eaf0596.
  • Loading branch information
shouya committed Feb 4, 2024
1 parent 5f1cc99 commit 3d942e8
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/server/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl EndpointConfig {
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct EndpointServiceConfig {
source: Option<String>,
content_type: Option<String>,
filters: Vec<FilterConfig>,
#[serde(default)]
client: Option<ClientConfig>,
Expand All @@ -57,6 +58,7 @@ pub struct EndpointServiceConfig {
#[derive(Clone)]
pub struct EndpointService {
source: Option<Url>,
content_type: Option<String>,
filters: Arc<Vec<BoxedFilter>>,
client: Arc<Client>,
}
Expand Down Expand Up @@ -234,6 +236,7 @@ impl EndpointService {

Ok(Self {
source,
content_type: config.content_type,
filters: Arc::new(filters),
client: Arc::new(client),
})
Expand Down Expand Up @@ -277,28 +280,25 @@ impl EndpointService {
}
}

const ACCEPTED_CONTENT_TYPES: [&'static str; 6] = [
"application/xml",
"text/xml",
"application/rss+xml",
"application/atom+xml",
"text/html",
"*/*",
];

async fn fetch_feed(&self, source: &Url) -> Result<Feed> {
let resp = self
.client
.get_with(source, |builder| {
builder.header("Accept", Self::ACCEPTED_CONTENT_TYPES.join(", "))
builder.header("Accept", "text/html,application/xml,text/xml,application/rss+xml,application/atom+xml")
})
.await?
.error_for_status()?;

let content_type = resp.content_type().map(|x| x.essence_str().to_owned());
let resp_content_type =
resp.content_type().map(|x| x.essence_str().to_owned());
let content_type = self
.content_type
.as_deref()
.or(resp_content_type.as_deref());

let content = resp.text()?;

let feed = match content_type.as_deref() {
let feed = match content_type {
Some("text/html") => Feed::from_html_content(&content, source)?,
Some("application/rss+xml") => Feed::from_rss_content(&content)?,
Some("application/atom+xml") => Feed::from_atom_content(&content)?,
Expand Down

0 comments on commit 3d942e8

Please sign in to comment.