Handle missing cookie file as connection failure
This commit is contained in:
parent
6efab9c8a2
commit
6bb837177c
|
@ -176,8 +176,8 @@ struct StaticCookie {
|
|||
}
|
||||
|
||||
impl CookieGetter for StaticCookie {
|
||||
fn get(&self) -> String {
|
||||
self.value.clone()
|
||||
fn get(&self) -> Result<String> {
|
||||
Ok(self.value.clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,8 +186,9 @@ struct CookieFile {
|
|||
}
|
||||
|
||||
impl CookieGetter for CookieFile {
|
||||
fn get(&self) -> String {
|
||||
read_cookie(&self.daemon_dir).unwrap()
|
||||
fn get(&self) -> Result<String> {
|
||||
read_cookie(&self.daemon_dir)
|
||||
.chain_err(|| ErrorKind::Connection("no cookie found".to_owned()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ impl MempoolEntry {
|
|||
}
|
||||
|
||||
pub trait CookieGetter: Send + Sync {
|
||||
fn get(&self) -> String;
|
||||
fn get(&self) -> Result<String>;
|
||||
}
|
||||
|
||||
struct Connection {
|
||||
|
@ -169,10 +169,10 @@ impl Connection {
|
|||
}
|
||||
|
||||
fn send(&mut self, request: &str) -> Result<()> {
|
||||
let cookie_b64 = base64::encode(&self.cookie_getter.get());
|
||||
let cookie = &self.cookie_getter.get()?;
|
||||
let msg = format!(
|
||||
"POST / HTTP/1.1\nAuthorization: Basic {}\nContent-Length: {}\n\n{}",
|
||||
cookie_b64,
|
||||
base64::encode(cookie),
|
||||
request.len(),
|
||||
request,
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue
Block a user