Skip to content
This repository has been archived by the owner on Mar 2, 2021. It is now read-only.

Commit

Permalink
Fix keep-alive issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kpcyrd committed Jan 9, 2017
1 parent f1816a0 commit e7dfdb7
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
132 changes: 132 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ authors = ["kpcyrd"]
[dependencies]
nickel = "*"
rustc-serialize = "0.3.22"
hyper = "0.9.14"
11 changes: 11 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
extern crate hyper;
extern crate rustc_serialize;
#[macro_use] extern crate nickel;

Expand All @@ -6,6 +7,7 @@ use std::io::prelude::*;
use std::collections::{ HashMap, BTreeMap };
use std::process::{ Command, Stdio };

use hyper::header::Connection;
use nickel::status::StatusCode;
use nickel::{ Nickel, HttpRouter, JsonBody, Mountable, StaticFilesHandler, MediaType, MiddlewareResult, Request, Response };
use rustc_serialize::json::{ Json, ToJson };
Expand Down Expand Up @@ -75,10 +77,19 @@ fn logger_fn<'mw>(req: &mut Request, res: Response<'mw>) -> MiddlewareResult<'mw
res.next_middleware()
}

fn no_keepalive<'mw>(_: &mut Request, mut res: Response<'mw>) -> MiddlewareResult<'mw> {
// this is a workaround for broken keep-alive (people on irc say it's in hyper)
println!("adding Connection: close");
res.set(Connection::close());
res.next_middleware()
}


fn main() {
let mut server = Nickel::new();

server.utilize(logger_fn);
server.utilize(no_keepalive);

server.get("/", middleware! { |_, res|
let mut data = HashMap::new();
Expand Down

0 comments on commit e7dfdb7

Please sign in to comment.