mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Add a FileManager to FetchContext.
This commit is contained in:
parent
d820387758
commit
fc68e0a6ca
4 changed files with 66 additions and 38 deletions
|
@ -6,6 +6,7 @@ use connector::create_http_connector;
|
||||||
use data_loader::decode;
|
use data_loader::decode;
|
||||||
use devtools_traits::DevtoolsControlMsg;
|
use devtools_traits::DevtoolsControlMsg;
|
||||||
use fetch::cors_cache::CORSCache;
|
use fetch::cors_cache::CORSCache;
|
||||||
|
use filemanager_thread::{FileManager, UIProvider};
|
||||||
use http_loader::{HttpState, set_default_accept_encoding, set_request_cookies};
|
use http_loader::{HttpState, set_default_accept_encoding, set_request_cookies};
|
||||||
use http_loader::{NetworkHttpRequestFactory, ReadResult, StreamedResponse, obtain_response, read_block};
|
use http_loader::{NetworkHttpRequestFactory, ReadResult, StreamedResponse, obtain_response, read_block};
|
||||||
use http_loader::{auth_from_cache, determine_request_referrer};
|
use http_loader::{auth_from_cache, determine_request_referrer};
|
||||||
|
@ -50,23 +51,28 @@ enum Data {
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FetchContext {
|
pub struct FetchContext<UI: 'static + UIProvider> {
|
||||||
pub state: HttpState,
|
pub state: HttpState,
|
||||||
pub user_agent: Cow<'static, str>,
|
pub user_agent: Cow<'static, str>,
|
||||||
pub devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
pub devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
||||||
|
pub filemanager: FileManager<UI>,
|
||||||
}
|
}
|
||||||
|
|
||||||
type DoneChannel = Option<(Sender<Data>, Receiver<Data>)>;
|
type DoneChannel = Option<(Sender<Data>, Receiver<Data>)>;
|
||||||
|
|
||||||
/// [Fetch](https://fetch.spec.whatwg.org#concept-fetch)
|
/// [Fetch](https://fetch.spec.whatwg.org#concept-fetch)
|
||||||
pub fn fetch(request: Rc<Request>, target: &mut Target, context: FetchContext) -> Response {
|
pub fn fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
|
target: &mut Target,
|
||||||
|
context: FetchContext<UI>)
|
||||||
|
-> Response {
|
||||||
fetch_with_cors_cache(request, &mut CORSCache::new(), target, context)
|
fetch_with_cors_cache(request, &mut CORSCache::new(), target, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch_with_cors_cache(request: Rc<Request>,
|
pub fn fetch_with_cors_cache<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
cache: &mut CORSCache,
|
cache: &mut CORSCache,
|
||||||
target: &mut Target,
|
target: &mut Target,
|
||||||
context: FetchContext) -> Response {
|
context: FetchContext<UI>)
|
||||||
|
-> Response {
|
||||||
// Step 1
|
// Step 1
|
||||||
if request.window.get() == Window::Client {
|
if request.window.get() == Window::Client {
|
||||||
// TODO: Set window to request's client object if client is a Window object
|
// TODO: Set window to request's client object if client is a Window object
|
||||||
|
@ -131,9 +137,14 @@ pub fn fetch_with_cors_cache(request: Rc<Request>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [Main fetch](https://fetch.spec.whatwg.org/#concept-main-fetch)
|
/// [Main fetch](https://fetch.spec.whatwg.org/#concept-main-fetch)
|
||||||
fn main_fetch(request: Rc<Request>, cache: &mut CORSCache, cors_flag: bool,
|
fn main_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
recursive_flag: bool, target: &mut Target, done_chan: &mut DoneChannel,
|
cache: &mut CORSCache,
|
||||||
context: &FetchContext) -> Response {
|
cors_flag: bool,
|
||||||
|
recursive_flag: bool,
|
||||||
|
target: &mut Target,
|
||||||
|
done_chan: &mut DoneChannel,
|
||||||
|
context: &FetchContext<UI>)
|
||||||
|
-> Response {
|
||||||
// TODO: Implement main fetch spec
|
// TODO: Implement main fetch spec
|
||||||
|
|
||||||
// Step 1
|
// Step 1
|
||||||
|
@ -389,9 +400,12 @@ fn main_fetch(request: Rc<Request>, cache: &mut CORSCache, cors_flag: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [Basic fetch](https://fetch.spec.whatwg.org#basic-fetch)
|
/// [Basic fetch](https://fetch.spec.whatwg.org#basic-fetch)
|
||||||
fn basic_fetch(request: Rc<Request>, cache: &mut CORSCache,
|
fn basic_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
target: &mut Target, done_chan: &mut DoneChannel,
|
cache: &mut CORSCache,
|
||||||
context: &FetchContext) -> Response {
|
target: &mut Target,
|
||||||
|
done_chan: &mut DoneChannel,
|
||||||
|
context: &FetchContext<UI>)
|
||||||
|
-> Response {
|
||||||
let url = request.current_url();
|
let url = request.current_url();
|
||||||
|
|
||||||
match url.scheme() {
|
match url.scheme() {
|
||||||
|
@ -460,14 +474,15 @@ fn basic_fetch(request: Rc<Request>, cache: &mut CORSCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [HTTP fetch](https://fetch.spec.whatwg.org#http-fetch)
|
/// [HTTP fetch](https://fetch.spec.whatwg.org#http-fetch)
|
||||||
fn http_fetch(request: Rc<Request>,
|
fn http_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
cache: &mut CORSCache,
|
cache: &mut CORSCache,
|
||||||
cors_flag: bool,
|
cors_flag: bool,
|
||||||
cors_preflight_flag: bool,
|
cors_preflight_flag: bool,
|
||||||
authentication_fetch_flag: bool,
|
authentication_fetch_flag: bool,
|
||||||
target: &mut Target,
|
target: &mut Target,
|
||||||
done_chan: &mut DoneChannel,
|
done_chan: &mut DoneChannel,
|
||||||
context: &FetchContext) -> Response {
|
context: &FetchContext<UI>)
|
||||||
|
-> Response {
|
||||||
// This is a new async fetch, reset the channel we are waiting on
|
// This is a new async fetch, reset the channel we are waiting on
|
||||||
*done_chan = None;
|
*done_chan = None;
|
||||||
// Step 1
|
// Step 1
|
||||||
|
@ -631,13 +646,14 @@ fn http_fetch(request: Rc<Request>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [HTTP redirect fetch](https://fetch.spec.whatwg.org#http-redirect-fetch)
|
/// [HTTP redirect fetch](https://fetch.spec.whatwg.org#http-redirect-fetch)
|
||||||
fn http_redirect_fetch(request: Rc<Request>,
|
fn http_redirect_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
cache: &mut CORSCache,
|
cache: &mut CORSCache,
|
||||||
response: Rc<Response>,
|
response: Rc<Response>,
|
||||||
cors_flag: bool,
|
cors_flag: bool,
|
||||||
target: &mut Target,
|
target: &mut Target,
|
||||||
done_chan: &mut DoneChannel,
|
done_chan: &mut DoneChannel,
|
||||||
context: &FetchContext) -> Response {
|
context: &FetchContext<UI>)
|
||||||
|
-> Response {
|
||||||
// Step 1
|
// Step 1
|
||||||
assert_eq!(response.return_internal.get(), true);
|
assert_eq!(response.return_internal.get(), true);
|
||||||
|
|
||||||
|
@ -711,11 +727,12 @@ fn http_redirect_fetch(request: Rc<Request>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [HTTP network or cache fetch](https://fetch.spec.whatwg.org#http-network-or-cache-fetch)
|
/// [HTTP network or cache fetch](https://fetch.spec.whatwg.org#http-network-or-cache-fetch)
|
||||||
fn http_network_or_cache_fetch(request: Rc<Request>,
|
fn http_network_or_cache_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
credentials_flag: bool,
|
credentials_flag: bool,
|
||||||
authentication_fetch_flag: bool,
|
authentication_fetch_flag: bool,
|
||||||
done_chan: &mut DoneChannel,
|
done_chan: &mut DoneChannel,
|
||||||
context: &FetchContext) -> Response {
|
context: &FetchContext<UI>)
|
||||||
|
-> Response {
|
||||||
// TODO: Implement Window enum for Request
|
// TODO: Implement Window enum for Request
|
||||||
let request_has_no_window = true;
|
let request_has_no_window = true;
|
||||||
|
|
||||||
|
@ -1108,8 +1125,10 @@ fn http_network_fetch(request: Rc<Request>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [CORS preflight fetch](https://fetch.spec.whatwg.org#cors-preflight-fetch)
|
/// [CORS preflight fetch](https://fetch.spec.whatwg.org#cors-preflight-fetch)
|
||||||
fn cors_preflight_fetch(request: Rc<Request>, cache: &mut CORSCache,
|
fn cors_preflight_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
context: &FetchContext) -> Response {
|
cache: &mut CORSCache,
|
||||||
|
context: &FetchContext<UI>)
|
||||||
|
-> Response {
|
||||||
// Step 1
|
// Step 1
|
||||||
let mut preflight = Request::new(request.current_url(), Some(request.origin.borrow().clone()),
|
let mut preflight = Request::new(request.current_url(), Some(request.origin.borrow().clone()),
|
||||||
request.is_service_worker_global_scope, request.pipeline_id.get());
|
request.is_service_worker_global_scope, request.pipeline_id.get());
|
||||||
|
|
|
@ -592,6 +592,7 @@ impl CoreResourceManager {
|
||||||
};
|
};
|
||||||
let ua = self.user_agent.clone();
|
let ua = self.user_agent.clone();
|
||||||
let dc = self.devtools_chan.clone();
|
let dc = self.devtools_chan.clone();
|
||||||
|
let filemanager = self.filemanager.clone();
|
||||||
spawn_named(format!("fetch thread for {}", init.url), move || {
|
spawn_named(format!("fetch thread for {}", init.url), move || {
|
||||||
let request = Request::from_init(init);
|
let request = Request::from_init(init);
|
||||||
// XXXManishearth: Check origin against pipeline id (also ensure that the mode is allowed)
|
// XXXManishearth: Check origin against pipeline id (also ensure that the mode is allowed)
|
||||||
|
@ -599,7 +600,12 @@ impl CoreResourceManager {
|
||||||
// todo referrer policy?
|
// todo referrer policy?
|
||||||
// todo service worker stuff
|
// todo service worker stuff
|
||||||
let mut target = Some(Box::new(sender) as Box<FetchTaskTarget + Send + 'static>);
|
let mut target = Some(Box::new(sender) as Box<FetchTaskTarget + Send + 'static>);
|
||||||
let context = FetchContext { state: http_state, user_agent: ua, devtools_chan: dc };
|
let context = FetchContext {
|
||||||
|
state: http_state,
|
||||||
|
user_agent: ua,
|
||||||
|
devtools_chan: dc,
|
||||||
|
filemanager: filemanager,
|
||||||
|
};
|
||||||
fetch(Rc::new(request), &mut target, context);
|
fetch(Rc::new(request), &mut target, context);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
use devtools_traits::DevtoolsControlMsg;
|
use devtools_traits::DevtoolsControlMsg;
|
||||||
use devtools_traits::HttpRequest as DevtoolsHttpRequest;
|
use devtools_traits::HttpRequest as DevtoolsHttpRequest;
|
||||||
use devtools_traits::HttpResponse as DevtoolsHttpResponse;
|
use devtools_traits::HttpResponse as DevtoolsHttpResponse;
|
||||||
|
use filemanager_thread::{TestProvider, TEST_PROVIDER};
|
||||||
use http_loader::{expect_devtools_http_request, expect_devtools_http_response};
|
use http_loader::{expect_devtools_http_request, expect_devtools_http_response};
|
||||||
use hyper::LanguageTag;
|
use hyper::LanguageTag;
|
||||||
use hyper::header::{Accept, AccessControlAllowCredentials, AccessControlAllowHeaders, AccessControlAllowOrigin};
|
use hyper::header::{Accept, AccessControlAllowCredentials, AccessControlAllowHeaders, AccessControlAllowOrigin};
|
||||||
|
@ -22,6 +23,7 @@ use hyper::uri::RequestUri;
|
||||||
use msg::constellation_msg::{ReferrerPolicy, TEST_PIPELINE_ID};
|
use msg::constellation_msg::{ReferrerPolicy, TEST_PIPELINE_ID};
|
||||||
use net::fetch::cors_cache::CORSCache;
|
use net::fetch::cors_cache::CORSCache;
|
||||||
use net::fetch::methods::{FetchContext, fetch, fetch_with_cors_cache};
|
use net::fetch::methods::{FetchContext, fetch, fetch_with_cors_cache};
|
||||||
|
use net::filemanager_thread::FileManager;
|
||||||
use net::http_loader::HttpState;
|
use net::http_loader::HttpState;
|
||||||
use net_traits::FetchTaskTarget;
|
use net_traits::FetchTaskTarget;
|
||||||
use net_traits::request::{Origin, RedirectMode, Referrer, Request, RequestMode};
|
use net_traits::request::{Origin, RedirectMode, Referrer, Request, RequestMode};
|
||||||
|
@ -46,11 +48,12 @@ struct FetchResponseCollector {
|
||||||
sender: Sender<Response>,
|
sender: Sender<Response>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_fetch_context(dc: Option<Sender<DevtoolsControlMsg>>) -> FetchContext {
|
fn new_fetch_context(dc: Option<Sender<DevtoolsControlMsg>>) -> FetchContext<TestProvider> {
|
||||||
FetchContext {
|
FetchContext {
|
||||||
state: HttpState::new(),
|
state: HttpState::new(),
|
||||||
user_agent: DEFAULT_USER_AGENT.into(),
|
user_agent: DEFAULT_USER_AGENT.into(),
|
||||||
devtools_chan: dc,
|
devtools_chan: dc,
|
||||||
|
filemanager: FileManager::new(TEST_PROVIDER),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl FetchTaskTarget for FetchResponseCollector {
|
impl FetchTaskTarget for FetchResponseCollector {
|
||||||
|
|
|
@ -10,9 +10,9 @@ use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
const TEST_PROVIDER: &'static TestProvider = &TestProvider;
|
pub const TEST_PROVIDER: &'static TestProvider = &TestProvider;
|
||||||
|
|
||||||
struct TestProvider;
|
pub struct TestProvider;
|
||||||
|
|
||||||
impl UIProvider for TestProvider {
|
impl UIProvider for TestProvider {
|
||||||
fn open_file_dialog(&self, _path: &str, _patterns: Vec<FilterPattern>) -> Option<String> {
|
fn open_file_dialog(&self, _path: &str, _patterns: Vec<FilterPattern>) -> Option<String> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue