Skip to content

Commit ea6e643

Browse files
committed
Remove dead code and make some functions private
1 parent 228ee9f commit ea6e643

File tree

2 files changed

+7
-34
lines changed

2 files changed

+7
-34
lines changed

src/web/file.rs

+5-32
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
//! Database based file handler
22
33
use crate::storage::{Blob, Storage};
4-
use crate::{error::Result, Config, Metrics};
5-
use iron::{status, Handler, IronResult, Request, Response};
4+
use crate::{error::Result, Config};
5+
use iron::{status, Response};
66

77
#[derive(Debug)]
88
pub(crate) struct File(pub(crate) Blob);
99

1010
impl File {
1111
/// Gets file from database
12-
pub fn from_path(storage: &Storage, path: &str, config: &Config) -> Result<File> {
12+
pub(super) fn from_path(storage: &Storage, path: &str, config: &Config) -> Result<File> {
1313
let max_size = if path.ends_with(".html") {
1414
config.max_file_size_html
1515
} else {
@@ -20,7 +20,7 @@ impl File {
2020
}
2121

2222
/// Consumes File and creates a iron response
23-
pub fn serve(self) -> Response {
23+
pub(super) fn serve(self) -> Response {
2424
use iron::headers::{CacheControl, CacheDirective, ContentType, HttpDate, LastModified};
2525

2626
let mut response = Response::with((status::Ok, self.0.content));
@@ -44,38 +44,11 @@ impl File {
4444
}
4545

4646
/// Checks if mime type of file is "application/x-empty"
47-
pub fn is_empty(&self) -> bool {
47+
pub(super) fn is_empty(&self) -> bool {
4848
self.0.mime == "application/x-empty"
4949
}
5050
}
5151

52-
/// Database based file handler for iron
53-
///
54-
/// This is similar to staticfile crate, but its using getting files from database.
55-
pub struct DatabaseFileHandler;
56-
57-
impl Handler for DatabaseFileHandler {
58-
fn handle(&self, req: &mut Request) -> IronResult<Response> {
59-
let path = req.url.path().join("/");
60-
let storage = extension!(req, Storage);
61-
let config = extension!(req, Config);
62-
if let Ok(file) = File::from_path(&storage, &path, &config) {
63-
let metrics = extension!(req, Metrics);
64-
65-
// Because all requests that don't hit another handler go through here, we will get all
66-
// requests successful or not recorded by the RequestRecorder, so we inject an extra
67-
// "database success" route to keep track of how often we succeed vs 404
68-
metrics
69-
.routes_visited
70-
.with_label_values(&["database success"])
71-
.inc();
72-
Ok(file.serve())
73-
} else {
74-
Err(super::error::Nope::CrateNotFound.into())
75-
}
76-
}
77-
}
78-
7952
#[cfg(test)]
8053
mod tests {
8154
use super::*;

src/web/metrics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use iron::status::Status;
77
use prometheus::{Encoder, HistogramVec, TextEncoder};
88
use std::time::{Duration, Instant};
99

10-
pub fn metrics_handler(req: &mut Request) -> IronResult<Response> {
10+
pub(super) fn metrics_handler(req: &mut Request) -> IronResult<Response> {
1111
let metrics = extension!(req, Metrics);
1212
let pool = extension!(req, Pool);
1313
let queue = extension!(req, BuildQueue);
@@ -30,7 +30,7 @@ fn duration_to_seconds(d: Duration) -> f64 {
3030
d.as_secs() as f64 + nanos
3131
}
3232

33-
pub struct RequestRecorder {
33+
pub(super) struct RequestRecorder {
3434
handler: Box<dyn iron::Handler>,
3535
route_name: String,
3636
}

0 commit comments

Comments
 (0)