net: Remove glob imports added in #4405

This commit is contained in:
Tetsuharu OHZEKI 2014-12-18 20:36:20 +09:00
parent d7f38a8973
commit 07b1c0e652
8 changed files with 172 additions and 194 deletions

View file

@ -9,9 +9,6 @@
//! This library will eventually become the core of the Fetch crate
//! with CORSRequest being expanded into FetchRequest (etc)
use self::CORSCacheTaskMsg::*;
use self::HeaderOrMethod::*;
use hyper::method::Method;
use std::ascii::AsciiExt;
use std::comm::{Sender, Receiver, channel};
@ -31,14 +28,14 @@ pub enum HeaderOrMethod {
impl HeaderOrMethod {
fn match_header(&self, header_name: &str) -> bool {
match *self {
HeaderData(ref s) => s.as_slice().eq_ignore_ascii_case(header_name),
HeaderOrMethod::HeaderData(ref s) => s.as_slice().eq_ignore_ascii_case(header_name),
_ => false
}
}
fn match_method(&self, method: &Method) -> bool {
match *self {
MethodData(ref m) => m == method,
HeaderOrMethod::MethodData(ref m) => m == method,
_ => false
}
}
@ -160,7 +157,7 @@ impl CORSCache for BasicCORSCache {
Some(_) => true,
None => {
self.insert(CORSCacheEntry::new(request.origin, request.destination, new_max_age,
request.credentials, HeaderData(header_name.to_string())));
request.credentials, HeaderOrMethod::HeaderData(header_name.to_string())));
false
}
}
@ -175,7 +172,7 @@ impl CORSCache for BasicCORSCache {
Some(_) => true,
None => {
self.insert(CORSCacheEntry::new(request.origin, request.destination, new_max_age,
request.credentials, MethodData(method)));
request.credentials, HeaderOrMethod::MethodData(method)));
false
}
}
@ -209,43 +206,43 @@ pub type CORSCacheSender = Sender<CORSCacheTaskMsg>;
impl CORSCache for CORSCacheSender {
fn clear (&mut self, request: CacheRequestDetails) {
let (tx, rx) = channel();
self.send(Clear(request, tx));
self.send(CORSCacheTaskMsg::Clear(request, tx));
let _ = rx.recv_opt();
}
fn cleanup(&mut self) {
let (tx, rx) = channel();
self.send(Cleanup(tx));
self.send(CORSCacheTaskMsg::Cleanup(tx));
let _ = rx.recv_opt();
}
fn match_header(&mut self, request: CacheRequestDetails, header_name: &str) -> bool {
let (tx, rx) = channel();
self.send(MatchHeader(request, header_name.to_string(), tx));
self.send(CORSCacheTaskMsg::MatchHeader(request, header_name.to_string(), tx));
rx.recv_opt().unwrap_or(false)
}
fn match_header_and_update(&mut self, request: CacheRequestDetails, header_name: &str, new_max_age: uint) -> bool {
let (tx, rx) = channel();
self.send(MatchHeaderUpdate(request, header_name.to_string(), new_max_age, tx));
self.send(CORSCacheTaskMsg::MatchHeaderUpdate(request, header_name.to_string(), new_max_age, tx));
rx.recv_opt().unwrap_or(false)
}
fn match_method(&mut self, request: CacheRequestDetails, method: Method) -> bool {
let (tx, rx) = channel();
self.send(MatchMethod(request, method, tx));
self.send(CORSCacheTaskMsg::MatchMethod(request, method, tx));
rx.recv_opt().unwrap_or(false)
}
fn match_method_and_update(&mut self, request: CacheRequestDetails, method: Method, new_max_age: uint) -> bool {
let (tx, rx) = channel();
self.send(MatchMethodUpdate(request, method, new_max_age, tx));
self.send(CORSCacheTaskMsg::MatchMethodUpdate(request, method, new_max_age, tx));
rx.recv_opt().unwrap_or(false)
}
fn insert(&mut self, entry: CORSCacheEntry) {
let (tx, rx) = channel();
self.send(Insert(entry, tx));
self.send(CORSCacheTaskMsg::Insert(entry, tx));
let _ = rx.recv_opt();
}
}
@ -288,31 +285,31 @@ impl CORSCacheTask {
pub fn run(&mut self) {
loop {
match self.receiver.recv() {
Clear(request, tx) => {
CORSCacheTaskMsg::Clear(request, tx) => {
self.cache.clear(request);
tx.send(());
},
Cleanup(tx) => {
CORSCacheTaskMsg::Cleanup(tx) => {
self.cache.cleanup();
tx.send(());
},
MatchHeader(request, header, tx) => {
CORSCacheTaskMsg::MatchHeader(request, header, tx) => {
tx.send(self.cache.match_header(request, header.as_slice()));
},
MatchHeaderUpdate(request, header, new_max_age, tx) => {
CORSCacheTaskMsg::MatchHeaderUpdate(request, header, new_max_age, tx) => {
tx.send(self.cache.match_header_and_update(request, header.as_slice(), new_max_age));
},
MatchMethod(request, method, tx) => {
CORSCacheTaskMsg::MatchMethod(request, method, tx) => {
tx.send(self.cache.match_method(request, method));
},
MatchMethodUpdate(request, method, new_max_age, tx) => {
CORSCacheTaskMsg::MatchMethodUpdate(request, method, new_max_age, tx) => {
tx.send(self.cache.match_method_and_update(request, method, new_max_age));
},
Insert(entry, tx) => {
CORSCacheTaskMsg::Insert(entry, tx) => {
self.cache.insert(entry);
tx.send(());
},
ExitMsg => break
CORSCacheTaskMsg::ExitMsg => break
}
}
}

View file

@ -2,12 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use self::ContextFrameType::*;
use self::CredentialsMode::*;
use self::Referer::*;
use self::RequestMode::*;
use self::ResponseTainting::*;
use url::Url;
use hyper::method::{Get, Method};
use hyper::mime::{Mime, Text, Html, Charset, Utf8};
@ -101,19 +95,19 @@ impl Request {
preserve_content_codings: false,
skip_service_worker: false,
context: context,
context_frame_type: ContextNone,
context_frame_type: ContextFrameType::ContextNone,
origin: None,
force_origin_header: false,
same_origin_data: false,
referer: Client,
referer: Referer::Client,
authentication: false,
sync: false,
mode: NoCORS,
credentials_mode: Omit,
mode: RequestMode::NoCORS,
credentials_mode: CredentialsMode::Omit,
use_url_credentials: false,
manual_redirect: false,
redirect_count: 0,
response_tainting: Basic,
response_tainting: ResponseTainting::Basic,
cache: None
}
}

View file

@ -2,9 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use self::ResponseBody::*;
use self::ResponseType::*;
use url::Url;
use hyper::status::StatusCode;
use hyper::status::Ok as StatusOk;
@ -70,31 +67,31 @@ pub struct Response {
impl Response {
pub fn new() -> Response {
Response {
response_type: Default,
response_type: ResponseType::Default,
termination_reason: None,
url: None,
status: Some(StatusOk),
headers: Headers::new(),
body: Empty,
body: ResponseBody::Empty,
internal_response: None
}
}
pub fn network_error() -> Response {
Response {
response_type: Error,
response_type: ResponseType::Error,
termination_reason: None,
url: None,
status: None,
headers: Headers::new(),
body: Empty,
body: ResponseBody::Empty,
internal_response: None
}
}
pub fn is_network_error(&self) -> bool {
match self.response_type {
Error => true,
ResponseType::Error => true,
_ => false
}
}
@ -102,8 +99,8 @@ impl Response {
/// Convert to a filtered response, of type `filter_type`.
/// Do not use with type Error or Default
pub fn to_filtered(self, filter_type: ResponseType) -> Response {
assert!(filter_type != Error);
assert!(filter_type != Default);
assert!(filter_type != ResponseType::Error);
assert!(filter_type != ResponseType::Default);
if self.is_network_error() {
return self;
}
@ -111,8 +108,8 @@ impl Response {
let mut response = self.clone();
response.internal_response = Some(box self);
match filter_type {
Default | Error => unreachable!(),
Basic => {
ResponseType::Default | ResponseType::Error => unreachable!(),
ResponseType::Basic => {
let headers = old_headers.iter().filter(|header| {
match header.name().to_ascii_lower().as_slice() {
"set-cookie" | "set-cookie2" => false,
@ -122,7 +119,7 @@ impl Response {
response.headers = headers;
response.response_type = filter_type;
},
CORS => {
ResponseType::CORS => {
let headers = old_headers.iter().filter(|header| {
match header.name().to_ascii_lower().as_slice() {
"cache-control" | "content-language" |
@ -134,10 +131,10 @@ impl Response {
response.headers = headers;
response.response_type = filter_type;
},
Opaque => {
ResponseType::Opaque => {
response.headers = Headers::new();
response.status = None;
response.body = Empty;
response.body = ResponseBody::Empty;
}
}
response