mirror of
https://github.com/servo/servo.git
synced 2025-08-09 23:45:35 +01:00
Remove the HttpResponse trait.
This commit is contained in:
parent
87fd4a2d79
commit
f24be9ad51
1 changed files with 10 additions and 31 deletions
|
@ -23,7 +23,6 @@ use hyper::header::{Authorization, Basic, CacheControl, CacheDirective, ContentE
|
||||||
use hyper::header::{ContentLength, Encoding, Header, Headers, Host, IfMatch, IfRange};
|
use hyper::header::{ContentLength, Encoding, Header, Headers, Host, IfMatch, IfRange};
|
||||||
use hyper::header::{IfUnmodifiedSince, IfModifiedSince, IfNoneMatch, Location, Pragma, Quality};
|
use hyper::header::{IfUnmodifiedSince, IfModifiedSince, IfNoneMatch, Location, Pragma, Quality};
|
||||||
use hyper::header::{QualityItem, Referer, SetCookie, UserAgent, qitem};
|
use hyper::header::{QualityItem, Referer, SetCookie, UserAgent, qitem};
|
||||||
use hyper::http::RawStatus;
|
|
||||||
use hyper::method::Method;
|
use hyper::method::Method;
|
||||||
use hyper::net::Fresh;
|
use hyper::net::Fresh;
|
||||||
use hyper::status::StatusCode;
|
use hyper::status::StatusCode;
|
||||||
|
@ -102,13 +101,11 @@ impl Read for WrappedHttpResponse {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait HttpResponse: Read {
|
impl WrappedHttpResponse {
|
||||||
fn headers(&self) -> &Headers;
|
fn headers(&self) -> &Headers {
|
||||||
fn status(&self) -> StatusCode;
|
&self.response.headers
|
||||||
fn status_raw(&self) -> &RawStatus;
|
|
||||||
fn http_version(&self) -> String {
|
|
||||||
"HTTP/1.1".to_owned()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn content_encoding(&self) -> Option<Encoding> {
|
fn content_encoding(&self) -> Option<Encoding> {
|
||||||
let encodings = match self.headers().get::<ContentEncoding>() {
|
let encodings = match self.headers().get::<ContentEncoding>() {
|
||||||
Some(&ContentEncoding(ref encodings)) => encodings,
|
Some(&ContentEncoding(ref encodings)) => encodings,
|
||||||
|
@ -126,24 +123,6 @@ pub trait HttpResponse: Read {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HttpResponse for WrappedHttpResponse {
|
|
||||||
fn headers(&self) -> &Headers {
|
|
||||||
&self.response.headers
|
|
||||||
}
|
|
||||||
|
|
||||||
fn status(&self) -> StatusCode {
|
|
||||||
self.response.status
|
|
||||||
}
|
|
||||||
|
|
||||||
fn status_raw(&self) -> &RawStatus {
|
|
||||||
self.response.status_raw()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn http_version(&self) -> String {
|
|
||||||
self.response.version.to_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct NetworkHttpRequestFactory {
|
struct NetworkHttpRequestFactory {
|
||||||
pub connector: Arc<Pool<Connector>>,
|
pub connector: Arc<Pool<Connector>>,
|
||||||
}
|
}
|
||||||
|
@ -415,7 +394,7 @@ impl StreamedResponse {
|
||||||
StreamedResponse { metadata: m, decoder: d }
|
StreamedResponse { metadata: m, decoder: d }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_http_response(response: Box<HttpResponse>, m: Metadata) -> Result<StreamedResponse, LoadError> {
|
pub fn from_http_response(response: WrappedHttpResponse, m: Metadata) -> Result<StreamedResponse, LoadError> {
|
||||||
let decoder = match response.content_encoding() {
|
let decoder = match response.content_encoding() {
|
||||||
Some(Encoding::Gzip) => {
|
Some(Encoding::Gzip) => {
|
||||||
let result = GzDecoder::new(response);
|
let result = GzDecoder::new(response);
|
||||||
|
@ -442,10 +421,10 @@ impl StreamedResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Decoder {
|
enum Decoder {
|
||||||
Gzip(GzDecoder<Box<HttpResponse>>),
|
Gzip(GzDecoder<WrappedHttpResponse>),
|
||||||
Deflate(DeflateDecoder<Box<HttpResponse>>),
|
Deflate(DeflateDecoder<WrappedHttpResponse>),
|
||||||
Brotli(Decompressor<Box<HttpResponse>>),
|
Brotli(Decompressor<WrappedHttpResponse>),
|
||||||
Plain(Box<HttpResponse>)
|
Plain(WrappedHttpResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_devtools_request(request_id: String,
|
fn prepare_devtools_request(request_id: String,
|
||||||
|
@ -1181,7 +1160,7 @@ fn http_network_fetch(request: Rc<Request>,
|
||||||
let meta_status = meta.status.clone();
|
let meta_status = meta.status.clone();
|
||||||
let meta_headers = meta.headers.clone();
|
let meta_headers = meta.headers.clone();
|
||||||
spawn_named(format!("fetch worker thread"), move || {
|
spawn_named(format!("fetch worker thread"), move || {
|
||||||
match StreamedResponse::from_http_response(box res, meta) {
|
match StreamedResponse::from_http_response(res, meta) {
|
||||||
Ok(mut res) => {
|
Ok(mut res) => {
|
||||||
*res_body.lock().unwrap() = ResponseBody::Receiving(vec![]);
|
*res_body.lock().unwrap() = ResponseBody::Receiving(vec![]);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue