diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-12-23 19:47:35 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-12-23 19:47:35 +0200 |
commit | b4b08d6ff76e4948dda6e4c8c8d36154204650ae (patch) | |
tree | d7036df9084c70541575a61553f4863d4969485e /src/client.rs | |
parent | bdd56ecad41d75880ea07a2cb3cd233d450cc24d (diff) | |
download | obnam2-b4b08d6ff76e4948dda6e4c8c8d36154204650ae.tar.gz |
feat! only specify base URL of server, without /chunks
Diffstat (limited to 'src/client.rs')
-rw-r--r-- | src/client.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/client.rs b/src/client.rs index 41b8ae2..af8d65e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -90,11 +90,15 @@ impl BackupClient { &self.base_url } + fn chunks_url(&self) -> String { + format!("{}/chunks", self.base_url()) + } + pub fn has_chunk(&self, meta: &ChunkMeta) -> anyhow::Result<Option<ChunkId>> { trace!("has_chunk: url={:?}", self.base_url()); let req = self .client - .get(self.base_url()) + .get(&self.chunks_url()) .query(&[("sha256", meta.sha256())]) .build()?; @@ -123,7 +127,7 @@ impl BackupClient { pub fn upload_chunk(&self, meta: ChunkMeta, chunk: DataChunk) -> anyhow::Result<ChunkId> { let res = self .client - .post(self.base_url()) + .post(&self.chunks_url()) .header("chunk-meta", meta.to_json()) .body(chunk.data().to_vec()) .send()?; @@ -145,7 +149,7 @@ impl BackupClient { ) -> anyhow::Result<ChunkId> { let res = self .client - .post(self.base_url()) + .post(&self.chunks_url()) .header("chunk-meta", meta.to_json()) .body(serde_json::to_string(&gen)?) .send()?; @@ -176,7 +180,7 @@ impl BackupClient { } pub fn list_generations(&self) -> anyhow::Result<Vec<ChunkId>> { - let url = format!("{}/?generation=true", self.base_url()); + let url = format!("{}?generation=true", &self.chunks_url()); trace!("list_generations: url={:?}", url); let req = self.client.get(&url).build()?; let res = self.client.execute(req)?; @@ -189,7 +193,7 @@ impl BackupClient { } pub fn fetch_chunk(&self, chunk_id: &ChunkId) -> anyhow::Result<DataChunk> { - let url = format!("{}/{}", self.base_url(), chunk_id); + let url = format!("{}/{}", &self.chunks_url(), chunk_id); trace!("fetch_chunk: url={:?}", url); let req = self.client.get(&url).build()?; let res = self.client.execute(req)?; @@ -203,7 +207,7 @@ impl BackupClient { } pub fn fetch_generation(&self, gen_id: &str) -> anyhow::Result<GenerationChunk> { - let url = format!("{}/{}", self.base_url(), gen_id); + let url = format!("{}/{}", &self.chunks_url(), gen_id); trace!("fetch_generation: url={:?}", url); let req = self.client.get(&url).build()?; let res = self.client.execute(req)?; |