Skip to content

Commit e3b220a

Browse files
committed
Drop text/html accept header requirement
1 parent 46d3fd2 commit e3b220a

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
- **Breaking**: From now on, `WASTEBIN_BASE_URL` is only used for the QR code
1313
link but not for internal routing. Use a dedicated proxy server to do that if
1414
necessary.
15+
- **Breaking**: Always return HTML on `/:id` even if `text/html` is not in the
16+
Accept header. On the other hand, `/raw/:id` must be used to retrieve raw
17+
text.
1518
- Use the [two-face](https://docs.rs/two-face) crate for an extended syntax
1619
list.
1720
- Serve all CSS assets under hashed URL to avoid caching issues.

src/handlers/download.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ mod tests {
7373
assert_eq!(res.status(), StatusCode::SEE_OTHER);
7474

7575
let location = res.headers().get("location").unwrap().to_str()?;
76-
let res = client.get(&format!("{location}?dl=cpp")).send().await?;
76+
let res = client.get(&format!("/dl{location}.cpp")).send().await?;
7777
assert_eq!(res.status(), StatusCode::OK);
7878

7979
let content = res.text().await?;

src/handlers/html/paste.rs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use askama::Template;
88
use axum::extract::{Form, Path, State};
99
use axum::response::{IntoResponse, Response};
1010
use axum_extra::extract::SignedCookieJar;
11-
use http::{header, HeaderMap};
1211
use serde::Deserialize;
1312

1413
#[derive(Deserialize, Debug)]
@@ -34,7 +33,6 @@ pub async fn get(
3433
State(db): State<Database>,
3534
State(highlighter): State<Highlighter>,
3635
Path(id): Path<String>,
37-
headers: HeaderMap,
3836
jar: SignedCookieJar,
3937
form: Option<Form<PasswordForm>>,
4038
) -> Result<Response, ErrorResponse> {
@@ -56,27 +54,18 @@ pub async fn get(
5654
Err(err) => return Err(err),
5755
};
5856

59-
let accept_html = headers
60-
.get(header::ACCEPT)
61-
.and_then(|value| value.to_str().ok())
62-
.is_some_and(|value| value.contains("text/html"));
63-
64-
if accept_html {
65-
return Ok(get_html(
66-
page.clone(),
67-
cache,
68-
highlighter,
69-
key,
70-
data,
71-
can_be_cached,
72-
jar,
73-
password.is_some(),
74-
)
75-
.await
76-
.into_response());
77-
}
78-
79-
Ok(data.text.into_response())
57+
Ok(get_html(
58+
page.clone(),
59+
cache,
60+
highlighter,
61+
key,
62+
data,
63+
can_be_cached,
64+
jar,
65+
password.is_some(),
66+
)
67+
.await
68+
.into_response())
8069
}
8170
.await
8271
.map_err(|err| make_error(err, page))

0 commit comments

Comments
 (0)