Skip to content

Graceful shutdown after handling just one request (for a local server handling oauth flow) #2410

Closed Answered by yuezk
furkankly asked this question in Q&A
Discussion options

You must be logged in to vote

I implemented this with the tiny_http crate. Thus, we can easily control the main loop.

use tiny_http::{Server, Response};

let server = Server::http("0.0.0.0:8000").unwrap();

for request in server.incoming_requests() {
    println!("received request! method: {:?}, url: {:?}, headers: {:?}",
        request.method(),
        request.url(),
        request.headers()
    );

    let response = Response::from_string("hello world");
    request.respond(response);
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yuezk
Comment options

Answer selected by furkankly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants