Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My http client #2

Merged
merged 11 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flurl"
version = "0.5.3"
version = "0.6.0"
authors = ["Andrey <[email protected]>"]
edition = "2021"

Expand All @@ -24,6 +24,8 @@ hyper-util = { version = "*", features = ["tokio"] }

http-body-util = { version = "*" }

my-http-client = { tag = "0.1.0", git = "https://github.com/MyJetTools/my-http-client.git" }

lazy_static = "*"
async-trait = "*"
bytes = "*"
Expand All @@ -36,5 +38,4 @@ my-ssh = { tag = "0.1.1", git = "https://github.com/MyJetTools/my-ssh.git", opti

webpki-roots = "*"
webpki = "*"
tower-service = "*"
pem = "*"
11 changes: 10 additions & 1 deletion src/errors/fl_url_error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use my_http_client::MyHttpClientError;

#[derive(Debug)]
pub enum FlUrlError {
HyperError(hyper::Error),
Expand All @@ -11,9 +13,10 @@ pub enum FlUrlError {
CanNotEstablishConnection(String),
RustTlsError(my_tls::tokio_rustls::rustls::Error),
CanNotConvertToUtf8(std::str::Utf8Error),

MyHttpClientError(my_http_client::MyHttpClientError),
#[cfg(feature = "with-ssh")]
SshSessionError(my_ssh::SshSessionError),
ReadingHyperBodyError(String),
}

impl FlUrlError {
Expand All @@ -31,6 +34,12 @@ impl From<my_tls::tokio_rustls::rustls::Error> for FlUrlError {
}
}

impl From<MyHttpClientError> for FlUrlError {
fn from(value: MyHttpClientError) -> Self {
Self::MyHttpClientError(value)
}
}

#[cfg(feature = "with-ssh")]
impl FlUrlError {
pub fn is_ssh_session_error(&self) -> bool {
Expand Down
25 changes: 15 additions & 10 deletions src/fl_response.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
use std::{collections::HashMap, fmt::Debug};

use hyper::{body::Incoming, Response};
use hyper::StatusCode;
use serde::de::DeserializeOwned;

use crate::{FlUrlError, FlUrlReadingHeaderError, ResponseBody, UrlBuilderOwned};
use crate::{FlUrlError, FlUrlReadingHeaderError, ResponseBody, UrlBuilder};

pub struct FlUrlResponse {
pub url: UrlBuilderOwned,
status_code: u16,
pub url: UrlBuilder,
status_code: StatusCode,
response: ResponseBody,
}

impl Debug for FlUrlResponse {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("FlUrlResponse")
.field("url", &self.url)
.field("url", &self.url.as_str())
.field("status_code", &self.status_code)
.finish()
}
}

impl FlUrlResponse {
pub fn new(url: UrlBuilderOwned, response: Response<Incoming>) -> Self {
pub fn from_http1_response<
TStream: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + Sync + 'static,
>(
url: UrlBuilder,
response: my_http_client::http1::MyHttpResponse<TStream>,
) -> Self {
Self {
status_code: response.status().as_u16(),
response: ResponseBody::Incoming(response.into()),
status_code: response.status(),
response: ResponseBody::Hyper(Some(response.into_response())),
url,
}
}

pub fn into_hyper_response(self) -> Response<Incoming> {
pub fn into_hyper_response(self) -> my_http_client::HyperResponse {
self.response.into_hyper_response()
}

Expand Down Expand Up @@ -76,6 +81,6 @@ impl FlUrlResponse {
}

pub fn get_status_code(&self) -> u16 {
self.status_code
self.status_code.as_u16()
}
}
Loading
Loading