aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/http/curl_response.rs
blob: c6f5d7721500c3b20c3231bf1244c6c39f47d52d (plain)
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
//! ref: composer/src/Composer/Util/Http/CurlResponse.php

use indexmap::IndexMap;
use shirabe_php_shim::PhpMixed;

use super::response::Response;

#[derive(Debug)]
pub struct CurlResponse {
    pub(crate) inner: Response,
    curl_info: IndexMap<String, PhpMixed>,
}

impl CurlResponse {
    pub fn new(
        request: IndexMap<String, PhpMixed>,
        code: Option<i64>,
        headers: Vec<String>,
        body: Option<String>,
        curl_info: IndexMap<String, PhpMixed>,
    ) -> anyhow::Result<Result<Self, shirabe_php_shim::LogicException>> {
        match Response::new(request, code, headers, body)? {
            Ok(inner) => Ok(Ok(Self { inner, curl_info })),
            Err(e) => Ok(Err(e)),
        }
    }

    pub fn get_curl_info(&self) -> &IndexMap<String, PhpMixed> {
        &self.curl_info
    }
}