File: http_client.rs

package info (click to toggle)
rust-dockworker 0.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 920 kB
  • sloc: makefile: 2
file content (66 lines) | stat: -rw-r--r-- 1,625 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use http::{HeaderMap, Response};
use std::path::Path;
use http_body::Body;
use http_body_util::Full;
use bytes::Bytes;

/// A http client
#[async_trait::async_trait]
pub trait HttpClient {
    type Err: Send + 'static;
    type Incoming: Body;

    async fn get(&self, headers: &HeaderMap, path: &str) -> Result<Response<Vec<u8>>, Self::Err>;

    async fn get_stream(
        &self,
        headers: &HeaderMap,
        path: &str,
    ) -> Result<Response<Self::Incoming>, Self::Err>;

    async fn head(&self, headers: &HeaderMap, path: &str) -> Result<HeaderMap, Self::Err>;

    async fn post(
        &self,
        headers: &HeaderMap,
        path: &str,
        body: &str,
    ) -> Result<Response<Vec<u8>>, Self::Err>;

    async fn post_stream(
        &self,
        headers: &HeaderMap,
        path: &str,
        body: &str,
    ) -> Result<Response<Self::Incoming>, Self::Err>;

    async fn post_file(
        &self,
        headers: &HeaderMap,
        path: &str,
        file: &Path,
    ) -> Result<Response<Vec<u8>>, Self::Err>;

    async fn post_file_stream(
        &self,
        headers: &HeaderMap,
        path: &str,
        file: &Path,
    ) -> Result<Response<Self::Incoming>, Self::Err>;

    async fn delete(&self, headers: &HeaderMap, path: &str)
        -> Result<Response<Vec<u8>>, Self::Err>;

    async fn put_file(
        &self,
        headers: &HeaderMap,
        path: &str,
        file: &Path,
    ) -> Result<Response<Vec<u8>>, Self::Err>;
}

/// Access to inner HttpClient
pub trait HaveHttpClient {
    type Client: HttpClient;
    fn http_client(&self) -> &Self::Client;
}