minimal implementation of http_network_fetch for testing purposes

This commit is contained in:
Nikki 2015-12-29 16:27:51 -07:00
parent e94a530597
commit af310f7874
4 changed files with 124 additions and 24 deletions

View file

@ -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)

View file

@ -4,7 +4,7 @@
use hyper::header::Headers;
use hyper::status::StatusCode;
use net_traits::{CacheState, Response, ResponseBody, ResponseType};
use net_traits::{CacheState, HttpsState, Response, ResponseBody, ResponseType};
use std::ascii::AsciiExt;
use std::cell::RefCell;
use std::rc::Rc;
@ -27,6 +27,7 @@ impl ResponseMethods for Response {
headers: Headers::new(),
body: ResponseBody::Empty,
cache_state: CacheState::None,
https_state: HttpsState::None,
internal_response: None
}
}