Skip to content

Commit

Permalink
Use 403 Forbidden instead of 501 Not Implemented to handle disabled f…
Browse files Browse the repository at this point in the history
…eatures
  • Loading branch information
nabijaczleweli committed Dec 20, 2016
1 parent 5f0134c commit 005d753
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl HttpHandler {

fn handle_put(&self, req: &mut Request) -> IronResult<Response> {
if self.temp_directory.is_none() {
return self.handle_bad_method(req);
return self.handle_forbidden_method(req, "-w", "write requests");
}

let (req_p, _, url_err) = self.parse_requested_path(req);
Expand Down Expand Up @@ -221,7 +221,7 @@ impl HttpHandler {

fn handle_delete(&self, req: &mut Request) -> IronResult<Response> {
if self.temp_directory.is_none() {
return self.handle_bad_method(req);
return self.handle_forbidden_method(req, "-w", "write requests");
}

let (req_p, symlink, url_err) = self.parse_requested_path(req);
Expand Down Expand Up @@ -264,6 +264,20 @@ impl HttpHandler {
})
}

fn handle_forbidden_method(&self, req: &mut Request, switch: &str, desc: &str) -> IronResult<Response> {
println!("{} used disabled request method {} grouped under {}", req.remote_addr, req.method, desc);
Ok(Response::with((status::Forbidden,
Header(headers::Server(USER_AGENT.to_string())),
"text/html;charset=utf-8".parse::<mime::Mime>().unwrap(),
html_response(ERROR_HTML,
&["403 Forbidden",
"This feature is currently disabled.",
&format!("<p>Ask the server administrator to pass <samp>{}</samp> \
to the executable to enable support for {}.</p>",
switch,
desc)]))))
}

fn handle_bad_method(&self, req: &mut Request) -> IronResult<Response> {
println!("{} used invalid request method {}", req.remote_addr, req.method);
Ok(Response::with((status::NotImplemented,
Expand Down

0 comments on commit 005d753

Please sign in to comment.