Test setting response.body by fetching on a server

This commit is contained in:
Nikki 2016-01-18 15:12:31 -07:00
parent 03a0b73538
commit 4165786767
3 changed files with 39 additions and 7 deletions

View file

@ -17,10 +17,12 @@ use hyper::mime::{Attr, Mime, SubLevel, TopLevel, Value};
use hyper::status::StatusCode;
use net_traits::request::{CacheMode, Context, ContextFrameType, CredentialsMode};
use net_traits::request::{RedirectMode, Referer, Request, RequestMode, ResponseTainting};
use net_traits::response::{CacheState, HttpsState, Response, ResponseType, TerminationReason};
use net_traits::response::{CacheState, HttpsState, TerminationReason};
use net_traits::response::{Response, ResponseBody, ResponseType};
use net_traits::{AsyncFetchListener, Metadata};
use resource_thread::CancellationListener;
use std::ascii::AsciiExt;
use std::io::Read;
use std::rc::Rc;
use std::str::FromStr;
use std::thread;
@ -163,7 +165,8 @@ fn http_fetch(request: Rc<Request>,
// Step 3
if !request.skip_service_worker.get() && !request.is_service_worker_global_scope {
// TODO: Substep 1 (handle fetch unimplemented)
// Substep 1
// TODO (handle fetch unimplemented)
if let Some(ref res) = response {
@ -617,11 +620,15 @@ fn http_network_fetch(request: Rc<Request>,
let mut response = Response::new();
match wrapped_response {
Ok(res) => {
Ok(mut 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();
let mut body = vec![];
res.response.read_to_end(&mut body);
response.body = ResponseBody::Done(body);
},
Err(e) =>
response.termination_reason = Some(TerminationReason::Fatal)
@ -633,7 +640,7 @@ fn http_network_fetch(request: Rc<Request>,
// 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"
// TODO Servo needs to decide what ciphers are to be treated as "deprecated"
response.https_state = HttpsState::None;
// TODO how do I read request?
@ -656,9 +663,14 @@ fn http_network_fetch(request: Rc<Request>,
*response.url_list.borrow_mut() = request.url_list.borrow().clone();
// Step 7
// TODO this step isn't possible yet
// Step 8
if Response::is_network_error(&response) && request.cache_mode.get() == CacheMode::NoStore {
// TODO update response in the HTTP cache for request
}
// TODO these steps aren't possible yet
// Step 9
// Substep 1
// Substep 2

View file

@ -75,8 +75,7 @@ impl ResponseMethods for Response {
response.response_type = filter_type;
},
ResponseType::Opaque |
ResponseType::OpaqueRedirect => {
ResponseType::Opaque | ResponseType::OpaqueRedirect => {
response.headers = Headers::new();
response.status = None;
response.body = ResponseBody::Empty;