diff options
author | Nikki <nikkicubed@gmail.com> | 2015-12-29 16:27:51 -0700 |
---|---|---|
committer | Nikki <nikkicubed@gmail.com> | 2016-01-05 12:14:07 -0700 |
commit | af310f7874119d5faf5e652a5eaf3be04cea06fc (patch) | |
tree | 0316f7c2e251c07bc5a4ad35b2d5c8808d1e74a8 /components/net/fetch/request.rs | |
parent | e94a5305977c12f740224129b93508feef6b19ef (diff) | |
download | servo-af310f7874119d5faf5e652a5eaf3be04cea06fc.tar.gz servo-af310f7874119d5faf5e652a5eaf3be04cea06fc.zip |
minimal implementation of http_network_fetch for testing purposes
Diffstat (limited to 'components/net/fetch/request.rs')
-rw-r--r-- | components/net/fetch/request.rs | 98 |
1 files changed, 92 insertions, 6 deletions
diff --git a/components/net/fetch/request.rs b/components/net/fetch/request.rs index 9ca2a6f5d70..8daf650c338 100644 --- a/components/net/fetch/request.rs +++ b/components/net/fetch/request.rs @@ -4,16 +4,20 @@ use fetch::cors_cache::{BasicCORSCache, CORSCache, CacheRequestDetails}; use fetch::response::ResponseMethods; +use http_loader::{NetworkHttpRequestFactory, WrappedHttpResponse}; +use http_loader::{create_http_connector, obtain_response}; +use hyper::client::response::Response as HyperResponse; use hyper::header::{Accept, IfMatch, IfRange, IfUnmodifiedSince, Location}; use hyper::header::{AcceptLanguage, ContentLength, ContentLanguage, HeaderView}; -use hyper::header::{Authorization, Basic}; +use hyper::header::{Authorization, Basic, ContentEncoding, Encoding}; use hyper::header::{ContentType, Header, Headers, IfModifiedSince, IfNoneMatch}; use hyper::header::{QualityItem, q, qitem, Referer as RefererHeader, UserAgent}; use hyper::method::Method; use hyper::mime::{Attr, Mime, SubLevel, TopLevel, Value}; use hyper::status::StatusCode; -use net_traits::{AsyncFetchListener, CacheState, Response}; -use net_traits::{ResponseType, Metadata}; +use net_traits::{AsyncFetchListener, CacheState, HttpsState, Response}; +use net_traits::{ResponseType, Metadata, TerminationReason}; +use resource_task::CancellationListener; use std::ascii::AsciiExt; use std::cell::RefCell; use std::rc::Rc; @@ -121,7 +125,7 @@ pub struct Request { pub use_url_credentials: bool, pub cache_mode: CacheMode, pub redirect_mode: RedirectMode, - pub redirect_count: usize, + pub redirect_count: u32, pub response_tainting: ResponseTainting } @@ -543,7 +547,6 @@ fn http_fetch(request: Rc<RefCell<Request>>, fn http_network_or_cache_fetch(request: Rc<RefCell<Request>>, credentials_flag: bool, authentication_fetch_flag: bool) -> Response { - // TODO: Implement HTTP network or cache fetch spec // TODO: Implement Window enum for Request let request_has_no_window = true; @@ -728,7 +731,90 @@ fn http_network_fetch(request: Rc<RefCell<Request>>, http_request: Rc<RefCell<Request>>, credentials_flag: bool) -> Response { // TODO: Implement HTTP network fetch spec - Response::network_error() + + // Step 1 + // nothing to do here, since credentials_flag is already a boolean + + // Step 2 + // TODO be able to create connection using current url's origin and credentials + let connection = create_http_connector(); + + // Step 3 + // TODO be able to tell if the connection is a failure + + // Step 4 + let factory = NetworkHttpRequestFactory { + connector: connection, + }; + let req = request.borrow(); + let url = req.current_url(); + let cancellation_listener = CancellationListener::new(None); + + let wrapped_response = obtain_response(&factory, &url, &req.method, &mut request.borrow_mut().headers, + &cancellation_listener, &None, &req.method, + &None, req.redirect_count, &None, ""); + + let mut response = Response::new(); + match wrapped_response { + Ok(res) => { + // is it okay for res.version to be unused? + response.url = Some(res.response.url.clone()); + response.status = Some(res.response.status); + response.headers = res.response.headers.clone(); + }, + Err(e) => + response.termination_reason = Some(TerminationReason::Fatal) + }; + + // TODO these substeps aren't possible yet + // Substep 1 + + // Substep 2 + + // TODO how can I tell if response was retrieved over HTTPS? + // TODO: Servo needs to decide what ciphers are to be treated as "deprecated" + response.https_state = HttpsState::None; + + // TODO how do I read request? + + // Step 5 + // TODO when https://bugzilla.mozilla.org/show_bug.cgi?id=1030660 + // is resolved, this step will become uneccesary + // TODO this step + if let Some(encoding) = response.headers.get::<ContentEncoding>() { + if encoding.contains(&Encoding::Gzip) { + + } + + else if encoding.contains(&Encoding::Compress) { + + } + }; + + // Step 6 + response.url_list = request.borrow().url_list.clone(); + + // Step 7 + + // Step 8 + + // Step 9 + // Substep 1 + // Substep 2 + // Substep 3 + // Substep 4 + + // Step 10 + // Substep 1 + // Substep 2 + // Sub-substep 1 + // Sub-substep 2 + // Sub-substep 3 + // Sub-substep 4 + // Substep 3 + + // Step 11 + response } /// [CORS preflight fetch](https://fetch.spec.whatwg.org#cors-preflight-fetch) |