Add new util_http crate

This commit is contained in:
Piotr Osiewicz 2023-06-23 17:21:02 +02:00
parent f34014b279
commit 37a74e8412
30 changed files with 84 additions and 33 deletions

22
Cargo.lock generated
View file

@ -609,6 +609,7 @@ dependencies = [
"tempdir", "tempdir",
"theme", "theme",
"util", "util",
"util_http",
"workspace", "workspace",
] ]
@ -1281,6 +1282,7 @@ dependencies = [
"tiny_http", "tiny_http",
"url", "url",
"util", "util",
"util_http",
"uuid 1.3.2", "uuid 1.3.2",
] ]
@ -1520,6 +1522,7 @@ dependencies = [
"smol", "smol",
"theme", "theme",
"util", "util",
"util_http",
] ]
[[package]] [[package]]
@ -3628,6 +3631,7 @@ dependencies = [
"unicase", "unicase",
"unindent", "unindent",
"util", "util",
"util_http",
] ]
[[package]] [[package]]
@ -4265,6 +4269,7 @@ dependencies = [
"serde_json", "serde_json",
"smol", "smol",
"util", "util",
"util_http",
] ]
[[package]] [[package]]
@ -5035,6 +5040,7 @@ dependencies = [
"toml", "toml",
"unindent", "unindent",
"util", "util",
"util_http",
] ]
[[package]] [[package]]
@ -7922,7 +7928,6 @@ dependencies = [
"dirs 3.0.2", "dirs 3.0.2",
"futures 0.3.28", "futures 0.3.28",
"git2", "git2",
"isahc",
"lazy_static", "lazy_static",
"log", "log",
"rand 0.8.5", "rand 0.8.5",
@ -7932,6 +7937,20 @@ dependencies = [
"smol", "smol",
"take-until", "take-until",
"tempdir", "tempdir",
]
[[package]]
name = "util_http"
version = "0.1.0"
dependencies = [
"anyhow",
"futures 0.3.28",
"isahc",
"log",
"serde",
"serde_json",
"smol",
"tempdir",
"url", "url",
] ]
@ -9036,6 +9055,7 @@ dependencies = [
"url", "url",
"urlencoding", "urlencoding",
"util", "util",
"util_http",
"uuid 1.3.2", "uuid 1.3.2",
"vim", "vim",
"welcome", "welcome",

View file

@ -64,6 +64,7 @@ members = [
"crates/theme", "crates/theme",
"crates/theme_selector", "crates/theme_selector",
"crates/util", "crates/util",
"crates/util_http",
"crates/vim", "crates/vim",
"crates/workspace", "crates/workspace",
"crates/welcome", "crates/welcome",

View file

@ -18,6 +18,7 @@ settings = { path = "../settings" }
theme = { path = "../theme" } theme = { path = "../theme" }
workspace = { path = "../workspace" } workspace = { path = "../workspace" }
util = { path = "../util" } util = { path = "../util" }
util_http = { path = "../util_http" }
anyhow.workspace = true anyhow.workspace = true
isahc.workspace = true isahc.workspace = true
lazy_static.workspace = true lazy_static.workspace = true

View file

@ -15,7 +15,7 @@ use smol::{fs::File, io::AsyncReadExt, process::Command};
use std::{ffi::OsString, sync::Arc, time::Duration}; use std::{ffi::OsString, sync::Arc, time::Duration};
use update_notification::UpdateNotification; use update_notification::UpdateNotification;
use util::channel::ReleaseChannel; use util::channel::ReleaseChannel;
use util::http::HttpClient; use util_http::HttpClient;
use workspace::Workspace; use workspace::Workspace;
const SHOULD_SHOW_UPDATE_NOTIFICATION_KEY: &str = "auto-updater-should-show-updated-notification"; const SHOULD_SHOW_UPDATE_NOTIFICATION_KEY: &str = "auto-updater-should-show-updated-notification";

View file

@ -16,6 +16,7 @@ collections = { path = "../collections" }
db = { path = "../db" } db = { path = "../db" }
gpui = { path = "../gpui" } gpui = { path = "../gpui" }
util = { path = "../util" } util = { path = "../util" }
util_http = { path = "../util_http" }
rpc = { path = "../rpc" } rpc = { path = "../rpc" }
settings = { path = "../settings" } settings = { path = "../settings" }
staff_mode = { path = "../staff_mode" } staff_mode = { path = "../staff_mode" }

View file

@ -41,7 +41,7 @@ use telemetry::Telemetry;
use thiserror::Error; use thiserror::Error;
use url::Url; use url::Url;
use util::channel::ReleaseChannel; use util::channel::ReleaseChannel;
use util::http::HttpClient; use util_http::HttpClient;
use util::{ResultExt, TryFutureExt}; use util::{ResultExt, TryFutureExt};
pub use rpc::*; pub use rpc::*;
@ -141,7 +141,7 @@ pub enum EstablishConnectionError {
#[error("{0}")] #[error("{0}")]
Other(#[from] anyhow::Error), Other(#[from] anyhow::Error),
#[error("{0}")] #[error("{0}")]
Http(#[from] util::http::Error), Http(#[from] util_http::Error),
#[error("{0}")] #[error("{0}")]
Io(#[from] std::io::Error), Io(#[from] std::io::Error),
#[error("{0}")] #[error("{0}")]
@ -1416,7 +1416,7 @@ mod tests {
use gpui::{executor::Deterministic, TestAppContext}; use gpui::{executor::Deterministic, TestAppContext};
use parking_lot::Mutex; use parking_lot::Mutex;
use std::future; use std::future;
use util::http::FakeHttpClient; use util_http::FakeHttpClient;
#[gpui::test(iterations = 10)] #[gpui::test(iterations = 10)]
async fn test_reconnection(cx: &mut TestAppContext) { async fn test_reconnection(cx: &mut TestAppContext) {

View file

@ -6,7 +6,7 @@ use parking_lot::Mutex;
use serde::Serialize; use serde::Serialize;
use std::{env, io::Write, mem, path::PathBuf, sync::Arc, time::Duration}; use std::{env, io::Write, mem, path::PathBuf, sync::Arc, time::Duration};
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
use util::http::HttpClient; use util_http::HttpClient;
use util::{channel::ReleaseChannel, TryFutureExt}; use util::{channel::ReleaseChannel, TryFutureExt};
use uuid::Uuid; use uuid::Uuid;

View file

@ -8,7 +8,7 @@ use rpc::{
ConnectionId, Peer, Receipt, TypedEnvelope, ConnectionId, Peer, Receipt, TypedEnvelope,
}; };
use std::{rc::Rc, sync::Arc}; use std::{rc::Rc, sync::Arc};
use util::http::FakeHttpClient; use util_http::FakeHttpClient;
pub struct FakeServer { pub struct FakeServer {
peer: Arc<Peer>, peer: Arc<Peer>,

View file

@ -7,7 +7,7 @@ use postage::{sink::Sink, watch};
use rpc::proto::{RequestMessage, UsersResponse}; use rpc::proto::{RequestMessage, UsersResponse};
use staff_mode::StaffMode; use staff_mode::StaffMode;
use std::sync::{Arc, Weak}; use std::sync::{Arc, Weak};
use util::http::HttpClient; use util_http::HttpClient;
use util::TryFutureExt as _; use util::TryFutureExt as _;
#[derive(Default, Debug)] #[derive(Default, Debug)]

View file

@ -28,6 +28,7 @@ theme = { path = "../theme" }
lsp = { path = "../lsp" } lsp = { path = "../lsp" }
node_runtime = { path = "../node_runtime"} node_runtime = { path = "../node_runtime"}
util = { path = "../util" } util = { path = "../util" }
util_http = { path = "../util_http" }
async-compression = { version = "0.3", features = ["gzip", "futures-bufread"] } async-compression = { version = "0.3", features = ["gzip", "futures-bufread"] }
async-tar = "0.4.2" async-tar = "0.4.2"
anyhow.workspace = true anyhow.workspace = true

View file

@ -29,8 +29,9 @@ use std::{
sync::Arc, sync::Arc,
}; };
use util::{ use util::{
fs::remove_matching, github::latest_github_release, http::HttpClient, paths, ResultExt, fs::remove_matching, paths, ResultExt,
}; };
use util_http::{HttpClient, github::latest_github_release};
const COPILOT_AUTH_NAMESPACE: &'static str = "copilot_auth"; const COPILOT_AUTH_NAMESPACE: &'static str = "copilot_auth";
actions!(copilot_auth, [SignIn, SignOut]); actions!(copilot_auth, [SignIn, SignOut]);

View file

@ -36,6 +36,7 @@ sum_tree = { path = "../sum_tree" }
text = { path = "../text" } text = { path = "../text" }
theme = { path = "../theme" } theme = { path = "../theme" }
util = { path = "../util" } util = { path = "../util" }
util_http = { path = "../util_http" }
anyhow.workspace = true anyhow.workspace = true
async-broadcast = "0.4" async-broadcast = "0.4"

View file

@ -46,7 +46,7 @@ use syntax_map::SyntaxSnapshot;
use theme::{SyntaxTheme, Theme}; use theme::{SyntaxTheme, Theme};
use tree_sitter::{self, Query}; use tree_sitter::{self, Query};
use unicase::UniCase; use unicase::UniCase;
use util::http::HttpClient; use util_http::HttpClient;
use util::{merge_json_value_into, post_inc, ResultExt, TryFutureExt as _, UnwrapFuture}; use util::{merge_json_value_into, post_inc, ResultExt, TryFutureExt as _, UnwrapFuture};
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]

View file

@ -10,6 +10,7 @@ doctest = false
[dependencies] [dependencies]
gpui = { path = "../gpui" } gpui = { path = "../gpui" }
util_http = { path = "../util_http" }
util = { path = "../util" } util = { path = "../util" }
async-compression = { version = "0.3", features = ["gzip", "futures-bufread"] } async-compression = { version = "0.3", features = ["gzip", "futures-bufread"] }
async-tar = "0.4.2" async-tar = "0.4.2"

View file

@ -11,7 +11,7 @@ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
sync::Arc, sync::Arc,
}; };
use util::http::HttpClient; use util_http::HttpClient;
const VERSION: &str = "v18.15.0"; const VERSION: &str = "v18.15.0";

View file

@ -36,6 +36,7 @@ settings = { path = "../settings" }
sum_tree = { path = "../sum_tree" } sum_tree = { path = "../sum_tree" }
terminal = { path = "../terminal" } terminal = { path = "../terminal" }
util = { path = "../util" } util = { path = "../util" }
util_http = { path = "../util_http" }
aho-corasick = "0.7" aho-corasick = "0.7"
anyhow.workspace = true anyhow.workspace = true

View file

@ -75,9 +75,10 @@ use std::{
}; };
use terminals::Terminals; use terminals::Terminals;
use util::{ use util::{
debug_panic, defer, http::HttpClient, merge_json_value_into, debug_panic, defer, merge_json_value_into,
paths::LOCAL_SETTINGS_RELATIVE_PATH, post_inc, ResultExt, TryFutureExt as _, paths::LOCAL_SETTINGS_RELATIVE_PATH, post_inc, ResultExt, TryFutureExt as _,
}; };
use util_http::HttpClient;
pub use fs::*; pub use fs::*;
pub use worktree::*; pub use worktree::*;
@ -681,7 +682,7 @@ impl Project {
) -> ModelHandle<Project> { ) -> ModelHandle<Project> {
let mut languages = LanguageRegistry::test(); let mut languages = LanguageRegistry::test();
languages.set_executor(cx.background()); languages.set_executor(cx.background());
let http_client = util::http::FakeHttpClient::with_404_response(); let http_client = util_http::FakeHttpClient::with_404_response();
let client = cx.update(|cx| client::Client::new(http_client.clone(), cx)); let client = cx.update(|cx| client::Client::new(http_client.clone(), cx));
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx)); let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
let project = let project =

View file

@ -9,7 +9,7 @@ path = "src/util.rs"
doctest = true doctest = true
[features] [features]
test-support = ["tempdir", "git2"] test-support = []
[dependencies] [dependencies]
anyhow.workspace = true anyhow.workspace = true
@ -17,15 +17,12 @@ backtrace = "0.3"
log.workspace = true log.workspace = true
lazy_static.workspace = true lazy_static.workspace = true
futures.workspace = true futures.workspace = true
isahc.workspace = true
smol.workspace = true smol.workspace = true
url = "2.2"
rand.workspace = true rand.workspace = true
rust-embed.workspace = true rust-embed.workspace = true
tempdir = { workspace = true, optional = true }
serde.workspace = true serde.workspace = true
serde_json.workspace = true serde_json.workspace = true
git2 = { version = "0.15", default-features = false, optional = true }
dirs = "3.0" dirs = "3.0"
take-until = "0.2.0" take-until = "0.2.0"

View file

@ -1,7 +1,5 @@
pub mod channel; pub mod channel;
pub mod fs; pub mod fs;
pub mod github;
pub mod http;
pub mod paths; pub mod paths;
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
pub mod test; pub mod test;

View file

@ -0,0 +1,22 @@
[package]
name = "util_http"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
isahc.workspace = true
anyhow.workspace = true
futures.workspace = true
serde_json.workspace = true
smol.workspace = true
serde.workspace = true
log.workspace = true
url = "2.2"
[features]
test-support = []
[dev-dependencies]
tempdir.workspace = true

View file

@ -1,4 +1,4 @@
use crate::http::HttpClient; use crate::HttpClient;
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use futures::AsyncReadExt; use futures::AsyncReadExt;
use serde::Deserialize; use serde::Deserialize;

View file

@ -1,3 +1,5 @@
pub mod github;
pub use anyhow::{anyhow, Result}; pub use anyhow::{anyhow, Result};
use futures::future::BoxFuture; use futures::future::BoxFuture;
use isahc::config::{Configurable, RedirectPolicy}; use isahc::config::{Configurable, RedirectPolicy};

View file

@ -63,6 +63,7 @@ terminal_view = { path = "../terminal_view" }
theme = { path = "../theme" } theme = { path = "../theme" }
theme_selector = { path = "../theme_selector" } theme_selector = { path = "../theme_selector" }
util = { path = "../util" } util = { path = "../util" }
util_http = { path = "../util_http" }
vim = { path = "../vim" } vim = { path = "../vim" }
workspace = { path = "../workspace" } workspace = { path = "../workspace" }
welcome = { path = "../welcome" } welcome = { path = "../welcome" }

View file

@ -6,10 +6,10 @@ use smol::fs::{self, File};
use std::{any::Any, path::PathBuf, sync::Arc}; use std::{any::Any, path::PathBuf, sync::Arc};
use util::{ use util::{
fs::remove_matching, fs::remove_matching,
github::{latest_github_release, GitHubLspBinaryVersion},
ResultExt, ResultExt,
}; };
use util_http::github::{latest_github_release, GitHubLspBinaryVersion};
pub struct CLspAdapter; pub struct CLspAdapter;
#[async_trait] #[async_trait]

View file

@ -15,10 +15,11 @@ use std::{
}; };
use util::{ use util::{
fs::remove_matching, fs::remove_matching,
github::{latest_github_release, GitHubLspBinaryVersion},
ResultExt, ResultExt,
}; };
use util_http::github::{latest_github_release, GitHubLspBinaryVersion};
pub struct ElixirLspAdapter; pub struct ElixirLspAdapter;
#[async_trait] #[async_trait]

View file

@ -17,8 +17,8 @@ use std::{
Arc, Arc,
}, },
}; };
use util::{fs::remove_matching, github::latest_github_release, ResultExt}; use util::{fs::remove_matching, ResultExt};
use util_http::github::latest_github_release;
fn server_binary_arguments() -> Vec<OsString> { fn server_binary_arguments() -> Vec<OsString> {
vec!["-mode=stdio".into()] vec!["-mode=stdio".into()]
} }

View file

@ -8,10 +8,10 @@ use smol::fs;
use std::{any::Any, env::consts, ffi::OsString, path::PathBuf}; use std::{any::Any, env::consts, ffi::OsString, path::PathBuf};
use util::{ use util::{
async_iife, async_iife,
github::{latest_github_release, GitHubLspBinaryVersion},
ResultExt, ResultExt,
}; };
use util_http::github::{latest_github_release, GitHubLspBinaryVersion};
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct LuaLspAdapter; pub struct LuaLspAdapter;

View file

@ -9,9 +9,10 @@ use smol::fs::{self, File};
use std::{any::Any, borrow::Cow, env::consts, path::PathBuf, str, sync::Arc}; use std::{any::Any, borrow::Cow, env::consts, path::PathBuf, str, sync::Arc};
use util::{ use util::{
fs::remove_matching, fs::remove_matching,
github::{latest_github_release, GitHubLspBinaryVersion},
ResultExt, ResultExt,
}; };
use util_http::github::{latest_github_release, GitHubLspBinaryVersion};
pub struct RustLspAdapter; pub struct RustLspAdapter;

View file

@ -16,9 +16,8 @@ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
sync::Arc, sync::Arc,
}; };
use util::{fs::remove_matching, github::latest_github_release}; use util::{fs::remove_matching, ResultExt};
use util::{github::GitHubLspBinaryVersion, ResultExt}; use util_http::github::{latest_github_release, GitHubLspBinaryVersion};
fn typescript_server_binary_arguments(server_path: &Path) -> Vec<OsString> { fn typescript_server_binary_arguments(server_path: &Path) -> Vec<OsString> {
vec![ vec![
server_path.into(), server_path.into(),

View file

@ -45,9 +45,10 @@ use std::{
use sum_tree::Bias; use sum_tree::Bias;
use terminal_view::{get_working_directory, TerminalSettings, TerminalView}; use terminal_view::{get_working_directory, TerminalSettings, TerminalView};
use util::{ use util::{
http::{self, HttpClient},
paths::PathLikeWithPosition, paths::PathLikeWithPosition,
}; };
use util_http::{self as http, HttpClient};
use welcome::{show_welcome_experience, FIRST_OPEN}; use welcome::{show_welcome_experience, FIRST_OPEN};
use fs::RealFs; use fs::RealFs;