Chunked encoding parser

This commit is contained in:
Tomasz Drwięga
2016-08-31 10:43:55 +02:00
parent 2a549386a6
commit bff847b90c
9 changed files with 355 additions and 24 deletions

View File

@@ -218,8 +218,8 @@ impl DappHandler for DappInstaller {
fn validate_and_install(&self, app_path: PathBuf) -> Result<Manifest, ValidationError> {
trace!(target: "dapps", "Opening dapp bundle at {:?}", app_path);
let mut file = try!(fs::File::open(app_path));
let hash = try!(sha3(&mut file));
let mut file_reader = io::BufReader::new(try!(fs::File::open(app_path)));
let hash = try!(sha3(&mut file_reader));
let dapp_id = try!(self.dapp_id.as_str().parse().map_err(|_| ValidationError::InvalidDappId));
if dapp_id != hash {
return Err(ValidationError::HashMismatch {
@@ -227,6 +227,7 @@ impl DappHandler for DappInstaller {
got: hash,
});
}
let file = file_reader.into_inner();
// Unpack archive
let mut zip = try!(zip::ZipArchive::new(file));
// First find manifest file

View File

@@ -33,7 +33,9 @@ pub struct GithubApp {
impl GithubApp {
pub fn url(&self) -> String {
format!("https://github.com/{}/{}/archive/{}.zip", self.account, self.repo, self.commit.to_hex())
// Since https fetcher doesn't support redirections we use direct link
// format!("https://github.com/{}/{}/archive/{}.zip", self.account, self.repo, self.commit.to_hex())
format!("https://codeload.github.com/{}/{}/zip/{}", self.account, self.repo, self.commit.to_hex())
}
fn commit(bytes: &[u8]) -> Option<[u8;COMMIT_LEN]> {

View File

@@ -16,7 +16,7 @@
//! Hyper Server Handler that fetches a file during a request (proxy).
use std::{fs, fmt};
use std::fmt;
use std::path::PathBuf;
use std::sync::mpsc;
use std::time::{Instant, Duration};
@@ -171,7 +171,8 @@ impl<H: DappHandler> server::Handler<HttpStream> for AppFetcherHandler<H> {
Ok(manifest) => FetchState::Done(manifest)
};
// Remove temporary zip file
let _ = fs::remove_file(path);
// TODO [todr] Uncomment me
// let _ = fs::remove_file(path);
(Some(state), Next::write())
},
Ok(Err(e)) => {