Skip to content

HTTP/1.0 request without "Keep-Alive", res.end() not close connection. #596

Closed
@AndrewTsao

Description

@AndrewTsao
extern crate hyper;
extern crate env_logger;

use std::io::Write;

use hyper::Server;
use hyper::server::{Request, Response};
use hyper::net::Fresh;
use hyper::header::{ContentLength};

fn hello(_: Request, mut res: Response<Fresh>) {
    let body = b"Hello World!";
    res.send(body).unwrap();
}

fn main() {
    env_logger::init().unwrap();
    println!("start listening on 3000");
    Server::http("127.0.0.1:3000").unwrap().handle_threads(hello, 3).unwrap();
}

I started server

RUST_LOG=trace ./target/debug/web-server

then I use `telnet command start a http request like this:

andi@andi-box:~/rust/web-server$ telnet localhost 3000
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.0 200 OK
Date: Sun, 05 Jul 2015 15:09:37 GMT
Content-Length: 12

Hello World!

but connection not closed.

DEBUG:hyper::server: Incoming stream
TRACE:hyper::buffer: read_into_buf pos=0, cap=4096
TRACE:hyper::buffer: slicing (0, 16, 4096)
TRACE:hyper::buffer: read_into_buf pos=16, cap=4096
TRACE:hyper::buffer: slicing (0, 18, 4096)
DEBUG:hyper::server::request: Request Line: Get AbsolutePath("/") Http10
DEBUG:hyper::server::request: Headers { }
TRACE:hyper::http: should_keep_alive( Http10, None )
TRACE:hyper::header: Headers.set( "Content-Length", ContentLength(12) )
DEBUG:hyper::server::response: writing head: Http10 Ok
TRACE:hyper::header: Headers.set( "Date", Date(HttpDate(Tm { tm_sec: 17, tm_min: 12, tm_hour: 15, tm_mday: 5, tm_mon: 6, tm_year: 115, tm_wday: 0, tm_yday: 185, tm_isdst: 0, tm_utcoff: 0, tm_nsec: 280907766 })) )
DEBUG:hyper::server::response: headers [
Headers { Content-Length: 12, Date: Sun, 05 Jul 2015 15:12:17 GMT, }]
DEBUG:hyper::server::response: write 12 bytes
TRACE:hyper::server::response: ending
TRACE:hyper::http: should_keep_alive( Http10, None )
DEBUG:hyper::server: keep_alive = true for 127.0.0.1:46167
TRACE:hyper::buffer: read_into_buf pos=0, cap=4096

The server trace log show connection is keeping alive. why?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions