File tree 4 files changed +22
-0
lines changed
4 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ mac = "0"
29
29
tendril = " 0.2"
30
30
heapsize = { version = " 0.1.1" , optional = true }
31
31
heapsize_plugin = { version = " 0.1.0" , optional = true }
32
+ hyper = {version = " 0.7" , optional = true }
32
33
33
34
[dev-dependencies ]
34
35
rustc-serialize = " 0.3.15"
Original file line number Diff line number Diff line change 10
10
11
11
set -ex
12
12
13
+ cargo build --features hyper
13
14
# Test without unstable first, to make sure src/tree_builder/rules.expanded.rs is up-to-date.
14
15
cargo test --no-run
15
16
cargo test | ./scripts/shrink-test-output.py
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ use std::borrow::Cow;
16
16
use std:: mem;
17
17
18
18
use encoding:: { self , EncodingRef } ;
19
+ #[ cfg( feature = "hyper" ) ] use hyper:: client:: IntoUrl ;
19
20
use string_cache:: QualName ;
20
21
use tendril;
21
22
use tendril:: { StrTendril , ByteTendril } ;
@@ -114,6 +115,23 @@ impl<Sink: TreeSink> Parser<Sink> {
114
115
opts : opts,
115
116
}
116
117
}
118
+
119
+ /// Fetch an HTTP or HTTPS URL with Hyper and parse.
120
+ #[ cfg( feature = "hyper" ) ]
121
+ pub fn from_http < U : IntoUrl > ( self , url : U ) -> Result < Sink :: Output , :: hyper:: Error > {
122
+ use hyper:: Client ;
123
+ use hyper:: header:: ContentType ;
124
+ use hyper:: mime:: Attr :: Charset ;
125
+ use encoding:: label:: encoding_from_whatwg_label;
126
+
127
+ let mut response = try!( Client :: new ( ) . get ( url) . send ( ) ) ;
128
+ let opts = BytesOpts {
129
+ transport_layer_encoding : response. headers . get :: < ContentType > ( )
130
+ . and_then ( |content_type| content_type. get_param ( Charset ) )
131
+ . and_then ( |charset| encoding_from_whatwg_label ( charset) )
132
+ } ;
133
+ Ok ( try!( self . from_bytes ( opts) . read_from ( & mut response) ) )
134
+ }
117
135
}
118
136
119
137
/// Options for choosing a character encoding
Original file line number Diff line number Diff line change 18
18
#[ cfg( feature = "heap_size" ) ]
19
19
extern crate heapsize;
20
20
21
+ #[ cfg( feature = "hyper" ) ] extern crate hyper;
22
+
21
23
#[ macro_use]
22
24
extern crate log;
23
25
You can’t perform that action at this time.
0 commit comments