Skip to content

Commit

Permalink
alternative workaround for hyperium/hyper#309
Browse files Browse the repository at this point in the history
  • Loading branch information
durka committed Aug 1, 2015
1 parent 5174f65 commit 14e0eba
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::sync::{Arc, Mutex, RwLock, mpsc};
use std::thread;
use std::thread::JoinHandle;
use std::collections::{HashMap, BTreeMap};
use std::io::Read;
use super::comms::{Controllable, CmdFrom, Block};
use super::stb::ParkState;
use self::iron::prelude::*;
Expand Down Expand Up @@ -350,6 +351,16 @@ macro_rules! params {
}
}

trait DrainableRequest {
fn drain(&mut self);
}

impl<'a, 'b> DrainableRequest for Request<'a, 'b> {
fn drain(&mut self) {
self.body.read_to_end(&mut vec![]);
}
}

/// Handler for starting/stopping a service
fn control(tx: mpsc::Sender<CmdFrom>) -> Box<Handler> {
let mtx = Mutex::new(tx);
Expand Down Expand Up @@ -379,7 +390,7 @@ fn control(tx: mpsc::Sender<CmdFrom>) -> Box<Handler> {
_ => Response::with((status::BadRequest, format!("What does {} mean?", action)))
};

response.headers.set(Connection::close());
req.drain();
Ok(response)
})
}
Expand Down Expand Up @@ -411,7 +422,7 @@ fn flow(tx: mpsc::Sender<CmdFrom>, flows: Arc<RwLock<Vec<Flow>>>) -> Box<Handler
_ => Response::with((status::BadRequest, format!("What does {} mean?", action)))
};

response.headers.set(Connection::close());
req.drain();
Ok(response)
})
}
Expand Down

0 comments on commit 14e0eba

Please sign in to comment.