summaryrefslogtreecommitdiffstats
path: root/src/http
diff options
context:
space:
mode:
authordev <dev@localhost>2026-11-20 18:49:22 +0000
committerdev <dev@localhost>2026-11-20 18:49:22 +0000
commit6c4b4394bd8ddf28d130e87e0100349f13f6e912 (patch)
treeebba70a9a141d05cb0251663aaacea858ec79115 /src/http
parent895f3547043def08f0822f936ae34458315f6982 (diff)
downloadaur-build-6c4b4394bd8ddf28d130e87e0100349f13f6e912.tar.gz
aur-build-6c4b4394bd8ddf28d130e87e0100349f13f6e912.zip
foundation, http: export what is used above you, and nothing else
The leaf modules were the widest liars. `git` exported 19 names of which 5 were named by nobody; `hash` exported a constant `EMPTY` that no code had ever referenced; `time` exported a virtual clock, an `advance` and a `wrap` whose only caller was a test that turned out not to exist. A leaf's interface is the whole contract the rest of the crate can rely on, and these interfaces were mostly decoration. Nine items were genuinely dead and are gone: `hash::EMPTY`, `git::{clone_source, count_commits, log_oneline, ls_remote_heads}`, `recipe::is_diffable`, `pkginfo::values_of`, `time::virtual_now`, and a free `time::advance` that had been shadowed by the `VirtualClock` method tests actually call. Eighteen more were used only inside their own module and are now private — `fetch`'s `Body` aside, which is the return type of a public parser and so is part of the interface whether or not anyone writes its name. http went 68 exported names to 27, and its last two glob re-exports (`pub(crate) use mutations::*; use pages::*;`) are explicit lists now. That makes the crate's glob count zero, so the allowlist in the architecture test is empty and can stay that way. Narrowing surfaced dead code that `pub` had been hiding, because a public item is presumed used and never questioned: `Req::query` and `Req::body` were parsed and stored and never read, `Res::found` had no callers, and `sse::FileBody` was a reader nobody constructed. All four are deleted rather than re-published to keep the warning quiet. git 19→14, hash 8→7, recipe 11→7, urlutil 2→1, config 35→31, pkgver 18→14, time 16→14, pkginfo 7→6, http 68→27. Crate totals: 585→516 pub, 219→115 dead, 4→0 globs. 281 passed / 0 failed, clippy -D warnings clean, release build clean, architecture 8/8.
Diffstat (limited to 'src/http')
-rw-r--r--src/http/auth.rs20
-rw-r--r--src/http/mod.rs13
-rw-r--r--src/http/render.rs48
-rw-r--r--src/http/routes/mod.rs17
-rw-r--r--src/http/routes/pages.rs8
-rw-r--r--src/http/sse.rs16
6 files changed, 53 insertions, 69 deletions
diff --git a/src/http/auth.rs b/src/http/auth.rs
index 6720607..0f174ef 100644
--- a/src/http/auth.rs
+++ b/src/http/auth.rs
@@ -28,7 +28,7 @@ fn counter() -> u64 {
C.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
}
-pub fn new_session() -> Option<String> {
+pub(crate) fn new_session() -> Option<String> {
let sid = random_hex()?;
if let Ok(mut s) = sessions().lock() {
s.insert(sid.clone(), false);
@@ -36,11 +36,11 @@ pub fn new_session() -> Option<String> {
Some(sid)
}
-pub fn is_valid_session(sid: &str) -> bool {
+pub(crate) fn is_valid_session(sid: &str) -> bool {
sessions().lock().map(|s| s.contains_key(sid)).unwrap_or(false)
}
-pub fn authenticate(sid: &str) {
+pub(crate) fn authenticate(sid: &str) {
if let Ok(mut s) = sessions().lock() {
if let Some(authenticated) = s.get_mut(sid) {
*authenticated = true;
@@ -48,21 +48,21 @@ pub fn authenticate(sid: &str) {
}
}
-pub fn is_authenticated(sid: &str) -> bool {
+pub(crate) fn is_authenticated(sid: &str) -> bool {
sessions().lock().map(|s| s.get(sid).copied().unwrap_or(false)).unwrap_or(false)
}
-pub fn drop_session(sid: &str) {
+pub(crate) fn drop_session(sid: &str) {
if let Ok(mut s) = sessions().lock() {
s.remove(sid);
}
}
-pub fn csrf_token(sid: &str) -> String {
+pub(crate) fn csrf_token(sid: &str) -> String {
hash::hex(format!("csrf|{sid}").as_bytes())[..32].to_string()
}
-pub fn csrf_ok(sid: &str, token: &str) -> bool {
+pub(crate) fn csrf_ok(sid: &str, token: &str) -> bool {
!token.is_empty() && is_valid_session(sid) && constant_time_eq(&csrf_token(sid), token)
}
@@ -78,7 +78,7 @@ fn constant_time_eq(a: &str, b: &str) -> bool {
diff == 0
}
-pub fn parse_cookies(header: &str) -> Vec<(String, String)> {
+pub(crate) fn parse_cookies(header: &str) -> Vec<(String, String)> {
header
.split(';')
.filter_map(|p| {
@@ -89,10 +89,10 @@ pub fn parse_cookies(header: &str) -> Vec<(String, String)> {
.collect()
}
-pub fn password_ok(cfg: &crate::config::Config, given: &str) -> bool {
+pub(crate) fn password_ok(cfg: &crate::config::Config, given: &str) -> bool {
cfg.password.is_empty() || constant_time_eq(&cfg.password, given)
}
-pub fn auth_required(cfg: &crate::config::Config) -> bool {
+pub(crate) fn auth_required(cfg: &crate::config::Config) -> bool {
!cfg.password.is_empty()
}
diff --git a/src/http/mod.rs b/src/http/mod.rs
index 0d78a00..5c34466 100644
--- a/src/http/mod.rs
+++ b/src/http/mod.rs
@@ -9,16 +9,14 @@ use std::sync::Arc;
use crate::config::Config;
use crate::db::Db;
-pub struct State {
+pub(crate) struct State {
pub cfg: Config,
pub db: Db,
}
-pub struct Req {
+pub(crate) struct Req {
pub method: String,
pub path: String,
- pub query: String,
- pub body: String,
pub cookies: Vec<(String, String)>,
pub query_pairs: Vec<(String, String)>,
pub form_pairs: Vec<(String, String)>,
@@ -40,7 +38,7 @@ impl Req {
}
}
-pub struct Res {
+pub(crate) struct Res {
pub status: u16,
pub content_type: String,
pub body: Vec<u8>,
@@ -76,9 +74,6 @@ impl Res {
stream_len: None,
}
}
- pub fn found(&self) -> bool {
- self.status < 400
- }
fn header(&mut self, name: &str, value: &str) {
self.headers.push((name.into(), value.into()));
}
@@ -137,8 +132,6 @@ fn serve(state: Arc<State>, mut request: tiny_http::Request) -> std::io::Result<
let req = Req {
method: request.method().as_str().to_string(),
path: percent_decode(&path),
- query: query.clone(),
- body,
cookies,
query_pairs: forms::parse(&query),
form_pairs,
diff --git a/src/http/render.rs b/src/http/render.rs
index f3e4669..fdf5676 100644
--- a/src/http/render.rs
+++ b/src/http/render.rs
@@ -51,14 +51,14 @@ impl Page {
#[derive(Template)]
#[template(path = "login.html")]
-pub struct Login {
+pub(crate) struct Login {
pub page: Page,
pub error: String,
}
#[derive(Template)]
#[template(path = "error.html")]
-pub struct ErrorPage {
+pub(crate) struct ErrorPage {
pub page: Page,
pub status: String,
pub message: String,
@@ -67,7 +67,7 @@ pub struct ErrorPage {
#[derive(Template)]
#[template(path = "dashboard.html")]
-pub struct Dashboard {
+pub(crate) struct Dashboard {
pub page: Page,
pub subscriptions: i64,
pub index_count: i64,
@@ -78,7 +78,7 @@ pub struct Dashboard {
}
#[derive(Debug, Clone)]
-pub struct PublishRow {
+pub(crate) struct PublishRow {
pub name: String,
pub version: String,
pub published_at: String,
@@ -88,13 +88,13 @@ pub struct PublishRow {
#[derive(Template)]
#[template(path = "reviews.html")]
-pub struct ReviewsPage {
+pub(crate) struct ReviewsPage {
pub page: Page,
pub rows: Vec<ReviewRow>,
}
#[derive(Debug, Clone)]
-pub struct ReviewRow {
+pub(crate) struct ReviewRow {
pub id: i64,
pub pkgbase: String,
pub version: String,
@@ -107,7 +107,7 @@ pub struct ReviewRow {
#[derive(Template)]
#[template(path = "review.html")]
-pub struct ReviewDetail {
+pub(crate) struct ReviewDetail {
pub page: Page,
pub c: ReviewHead,
pub base_version: String,
@@ -121,7 +121,7 @@ pub struct ReviewDetail {
}
#[derive(Debug, Clone)]
-pub struct ReviewHead {
+pub(crate) struct ReviewHead {
pub id: i64,
pub pkgbase: String,
pub version: String,
@@ -165,7 +165,7 @@ pub struct Subscriptions {
}
#[derive(Debug, Clone)]
-pub struct SubRow {
+pub(crate) struct SubRow {
pub name: String,
pub state: String,
pub maintainer: String,
@@ -191,7 +191,7 @@ pub struct Attention {
}
#[derive(Debug, Clone)]
-pub struct UnbuiltRow {
+pub(crate) struct UnbuiltRow {
pub pkgbase: String,
pub approved: String,
pub serving: String,
@@ -200,7 +200,7 @@ pub struct UnbuiltRow {
}
#[derive(Debug, Clone)]
-pub struct NoticeRow {
+pub(crate) struct NoticeRow {
pub id: i64,
pub pkgbase: String,
pub kind: String,
@@ -210,7 +210,7 @@ pub struct NoticeRow {
}
#[derive(Debug, Clone)]
-pub struct StaleRow {
+pub(crate) struct StaleRow {
pub pkgbase: String,
pub dependency: String,
pub built_with: String,
@@ -218,7 +218,7 @@ pub struct StaleRow {
}
#[derive(Debug, Clone)]
-pub struct BlockedRow {
+pub(crate) struct BlockedRow {
pub id: String,
pub id_short: String,
pub pkgbase: String,
@@ -235,7 +235,7 @@ pub struct Packages {
}
#[derive(Debug, Clone)]
-pub struct IndexRow {
+pub(crate) struct IndexRow {
pub name: String,
pub version: String,
pub arch: String,
@@ -245,7 +245,7 @@ pub struct IndexRow {
#[derive(Template)]
#[template(path = "package.html")]
-pub struct PackageDetail {
+pub(crate) struct PackageDetail {
pub page: Page,
pub name: String,
pub summary: String,
@@ -259,7 +259,7 @@ pub struct PackageDetail {
}
#[derive(Debug, Clone)]
-pub struct TimelineRow {
+pub(crate) struct TimelineRow {
pub version: String,
pub state: String,
pub aur_commit: String,
@@ -278,14 +278,14 @@ pub struct Builds {
#[derive(Template)]
#[template(path = "builds_table.html")]
-pub struct BuildsTable {
+pub(crate) struct BuildsTable {
pub page: Page,
pub rows: Vec<BuildRow>,
pub recent: Vec<BuildRow>,
}
#[derive(Debug, Clone)]
-pub struct BuildLite {
+pub(crate) struct BuildLite {
pub id: String,
pub id_short: String,
pub kind: String,
@@ -309,7 +309,7 @@ pub struct BuildRow {
#[derive(Template)]
#[template(path = "build.html")]
-pub struct BuildDetail {
+pub(crate) struct BuildDetail {
pub page: Page,
pub id: String,
pub id_short: String,
@@ -326,7 +326,7 @@ pub struct BuildDetail {
}
#[derive(Debug, Clone)]
-pub struct StepRow {
+pub(crate) struct StepRow {
pub step: String,
pub status: String,
pub attempt: i64,
@@ -343,7 +343,7 @@ pub struct Audit {
}
#[derive(Debug, Clone)]
-pub struct AuditRow {
+pub(crate) struct AuditRow {
pub at: String,
pub actor_kind: String,
pub actor: String,
@@ -355,19 +355,19 @@ pub struct AuditRow {
#[derive(Template)]
#[template(path = "settings.html")]
-pub struct Settings {
+pub(crate) struct Settings {
pub page: Page,
pub rows: Vec<SettingRow>,
pub repo: String,
}
#[derive(Debug, Clone)]
-pub struct SettingRow {
+pub(crate) struct SettingRow {
pub key: String,
pub value: String,
}
-pub fn static_asset(name: &str, accept_gzip: bool) -> crate::http::Res {
+pub(crate) fn static_asset(name: &str, accept_gzip: bool) -> crate::http::Res {
use crate::http::Res;
match name {
"app.css" => {
diff --git a/src/http/routes/mod.rs b/src/http/routes/mod.rs
index ed488c8..7495524 100644
--- a/src/http/routes/mod.rs
+++ b/src/http/routes/mod.rs
@@ -8,10 +8,17 @@ use super::{Req, Res, State};
mod mutations;
mod pages;
-pub(crate) use mutations::*;
-pub(crate) use pages::*;
-
-pub fn gate(state: &State, req: &Req, sid: &str) -> Option<Res> {
+pub(crate) use mutations::{
+ build_cancel, build_retry, notice_ack, package_rebuild, package_withdraw, review_approve,
+ review_reject, reviews_bulk, sub_add, sub_pause, sub_remove,
+};
+pub(crate) use pages::{
+ attention, audit, build_detail, build_log, build_log_stream, builds_page, builds_with,
+ dashboard, metrics, package_detail, packages, panels_base, review_body, review_detail,
+ review_rows, reviews, settings, subscriptions,
+};
+
+pub(crate) fn gate(state: &State, req: &Req, sid: &str) -> Option<Res> {
if !auth::auth_required(&state.cfg) {
return None;
}
@@ -21,7 +28,7 @@ pub fn gate(state: &State, req: &Req, sid: &str) -> Option<Res> {
Some(Res::redirect("/login"))
}
-pub fn login_form(state: &State, req: &Req) -> Res {
+pub(crate) fn login_form(state: &State, req: &Req) -> Res {
let page = Page::new("Sign in", csrf(state, req));
page_to_res(Login { page, error: String::new() }, 200)
}
diff --git a/src/http/routes/pages.rs b/src/http/routes/pages.rs
index bb5db34..e8590b0 100644
--- a/src/http/routes/pages.rs
+++ b/src/http/routes/pages.rs
@@ -70,7 +70,7 @@ pub(crate) fn reviews(state: &State, req: &Req) -> Res {
page_to_res(ReviewsPage { page, rows: review_rows(&state.db) }, 200)
}
-pub(crate) fn full_version(c: &CandidateRow) -> String {
+fn full_version(c: &CandidateRow) -> String {
crate::pkgver::full_version(&c.epoch, &c.pkgver, &c.pkgrel)
}
@@ -368,7 +368,7 @@ pub(crate) fn package_detail(state: &State, req: &Req, name: &str) -> Res {
// --------------------------------------------------------------- builds --
-pub(crate) fn build_version(db: &Db, b: &builds::BuildRow) -> String {
+fn build_version(db: &Db, b: &builds::BuildRow) -> String {
if let Some(cid) = b.candidate_id {
if let Some(c) = candidates::candidate_by_id(db, cid).ok().flatten() {
return c.version();
@@ -382,7 +382,7 @@ pub(crate) fn build_version(db: &Db, b: &builds::BuildRow) -> String {
String::new()
}
-pub(crate) fn build_rows(state: &State) -> Vec<BuildRow> {
+fn build_rows(state: &State) -> Vec<BuildRow> {
builds::list(
&state.db,
BuildState::active(),
@@ -424,7 +424,7 @@ pub(crate) fn builds_page(state: &State, req: &Req) -> Res {
builds_with(state, req, page)
}
-pub(crate) fn recent_rows(state: &State) -> Vec<BuildRow> {
+fn recent_rows(state: &State) -> Vec<BuildRow> {
builds::list(&state.db, &[BuildState::Failed, BuildState::Succeeded], 10)
.unwrap_or_default()
.into_iter()
diff --git a/src/http/sse.rs b/src/http/sse.rs
index 39266be..bceba9f 100644
--- a/src/http/sse.rs
+++ b/src/http/sse.rs
@@ -117,19 +117,3 @@ fn read_from(path: &Path, offset: u64) -> (Vec<u8>, bool) {
let grew = !buf.is_empty();
(buf, grew)
}
-
-pub struct FileBody {
- inner: std::io::Cursor<Vec<u8>>,
-}
-
-impl FileBody {
- pub fn new(bytes: Vec<u8>) -> Self {
- Self { inner: std::io::Cursor::new(bytes) }
- }
-}
-
-impl Read for FileBody {
- fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
- self.inner.read(buf)
- }
-}