-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
100 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,6 @@ insert_final_newline = true | |
|
||
[*.{yaml,yml}] | ||
indent_size = 2 | ||
|
||
[Makefile] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.PHONY: build | ||
build: | ||
cargo build | ||
|
||
.PHONY: test | ||
test: | ||
cargo test | ||
|
||
.PHONY: bench | ||
bench: | ||
cargo bench -p isahc-benchmarks | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use rouille::{Request, Response}; | ||
use std::net::SocketAddr; | ||
use std::thread; | ||
use std::sync::Arc; | ||
|
||
pub struct TestServer { | ||
addr: SocketAddr, | ||
counter: Option<Arc<()>>, | ||
handle: Option<thread::JoinHandle<()>>, | ||
} | ||
|
||
impl TestServer { | ||
pub fn static_response(body: &'static [u8]) -> Self { | ||
Self::new(move |_| { | ||
use std::io::Cursor; | ||
|
||
rouille::Response { | ||
status_code: 200, | ||
headers: vec![], | ||
data: rouille::ResponseBody::from_reader(Cursor::new(body)), | ||
upgrade: None, | ||
} | ||
}) | ||
} | ||
|
||
pub fn new(handler: impl Send + Sync + 'static + Fn(&Request) -> Response) -> Self { | ||
let server = rouille::Server::new("localhost:0", handler).unwrap(); | ||
let addr = server.server_addr(); | ||
|
||
let counter_outer = Arc::new(()); | ||
let counter_inner = counter_outer.clone(); | ||
let handle = thread::spawn(move || { | ||
while Arc::strong_count(&counter_inner) > 1 { | ||
server.poll(); | ||
} | ||
}); | ||
|
||
Self { | ||
addr: addr, | ||
counter: Some(counter_outer), | ||
handle: Some(handle), | ||
} | ||
} | ||
|
||
pub fn endpoint(&self) -> String { | ||
format!("http://{}", self.addr) | ||
} | ||
} | ||
|
||
impl Drop for TestServer { | ||
fn drop(&mut self) { | ||
self.counter.take(); | ||
self.handle.take().unwrap().join().unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters