Function called twice in simple web server using Iron

112 Views Asked by At

I have a super simple web server, and for some reason the println! statement is printed out twice. Why could this be?

extern crate iron;

use iron::prelude::*;
use iron::status;

fn hello_world(_: &mut Request) -> IronResult<Response> {
    println!("Said Hello World");
    Ok(Response::with((status::Ok, "Hello World\n")))
}

fn main() {
    Iron::new(hello_world).http("localhost:8000").unwrap();
}

Every time I refresh my browser the output in the shell is:

Said Hello World
Said Hello World

I would only expect the line to be printed out once.It seems that my hello_world functions is being called twice. What am I missing?

1

There are 1 best solutions below

1
On BEST ANSWER

Your browser might be automatically trying to fetch favicon.ico. Check the contents of the Request to know for sure! :) Your browser may also have a network monitor as part of its developer tools; this should show you the request for favicon.ico (I know it does in Firefox, don't know about other browsers).