Skip to content

Commit 771b43c

Browse files
committed
Return HttpResult<Listening> from serve()
This can be used to stop the server again, by calling the `close()` method on the `Listening` instance. Because Iron doesn't re-publish the `Listening` type, we need to add Hyper as a dependency. See iron/iron#406. This change allows us to add integration tests that test the server output.
1 parent a88cfd2 commit 771b43c

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Possible log types:
1515
### UNRELEASED
1616

1717
- [changed] Removed datastore module, use Redis directly (#10)
18+
- [changed] SpaceapiServer.serve() now returns a HttpResult<Listening> (#16)
1819
- [added] Support status modifiers (#8)
1920

2021
### v0.1.1 (2015-11-16)

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ include = [
2323
redis = "^0.5"
2424
rustc-serialize = "^0.3"
2525
iron = "^0.2"
26+
hyper = "^0.7"
2627
log = "^0.3"
2728
urlencoded = "^0.2"
2829
router = "^0.0.15"

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
#[macro_use] extern crate error_type;
77
extern crate rustc_serialize;
88
extern crate iron;
9+
extern crate hyper;
910
#[macro_use] extern crate router;
1011
extern crate urlencoded;
1112
extern crate redis;
1213
extern crate spaceapi;
1314

1415
pub use spaceapi as api;
16+
pub use iron::error::HttpResult;
17+
pub use hyper::server::Listening;
1518

1619
mod server;
1720
mod errors;

src/server/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,17 @@ impl SpaceapiServer {
6161

6262
/// Start a HTTP server listening on ``self.host:self.port``.
6363
///
64-
/// This call is blocking. It can be interrupted with SIGINT (Ctrl+C).
65-
pub fn serve(self) {
64+
/// The call returns an `HttpResult<Listening>` object, see
65+
/// http://ironframework.io/doc/hyper/server/struct.Listening.html
66+
/// for more information.
67+
pub fn serve(self) -> ::HttpResult<::Listening> {
6668
let host = self.host;
6769
let port = self.port;
6870

6971
let router = self.route();
7072

7173
println!("Starting HTTP server on http://{}:{}...", host, port);
72-
Iron::new(router).http((host, port)).unwrap();
74+
Iron::new(router).http((host, port))
7375
}
7476

7577
/// Register a new sensor.

0 commit comments

Comments
 (0)