11extern crate clap;
22extern crate hyper;
33extern crate url;
4+ extern crate futures;
5+ extern crate tokio_core;
46
57use clap:: { Arg , ArgMatches , App } ;
6- use hyper:: { Method , Request , Uri } ;
8+ use hyper:: { Client , Method , Request , Uri } ;
79use hyper:: header:: Authorization ;
810use hyper:: header;
911use std:: str:: FromStr ;
1012use url:: { Url } ;
13+ use tokio_core:: reactor:: Core ;
14+ use futures:: { Future , Stream } ;
15+ use std:: io:: { self , Write } ;
1116
1217fn main ( ) {
1318 match ClientConfig :: from_cli_args ( ) {
@@ -21,12 +26,30 @@ fn main() {
2126 } ;
2227}
2328
24- fn make_test_request ( config : & ClientConfig ) -> ( ) {
29+ fn make_test_request ( config : & ClientConfig ) {
2530 let uri = config. api_uri ( & [ "x" , "projects" ] ) ;
2631
2732 let mut req = Request :: new ( Method :: Get , uri) ;
2833 config. auth_info . apply_to ( & mut req) ;
2934 println ! ( "Request:\n {:?}" , req) ;
35+
36+ let mut core = Core :: new ( )
37+ . expect ( "Failed to create an event loop for making HTTP requests" ) ;
38+ let client = Client :: new ( & core. handle ( ) ) ;
39+
40+ let work = client. request ( req) . and_then ( |res| {
41+ println ! ( "Response: {}" , res. status( ) ) ;
42+
43+ res. body ( ) . for_each ( |chunk| {
44+ io:: stdout ( )
45+ . write_all ( & chunk)
46+ . map ( |_| ( ) )
47+ . map_err ( From :: from)
48+ } )
49+ } ) ;
50+
51+ core. run ( work)
52+ . expect ( "Failed to make request" ) ;
3053}
3154
3255/// Connection information for Code Dx.
0 commit comments