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

View file

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

View file

@ -18,6 +18,7 @@ settings = { path = "../settings" }
theme = { path = "../theme" }
workspace = { path = "../workspace" }
util = { path = "../util" }
util_http = { path = "../util_http" }
anyhow.workspace = true
isahc.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 update_notification::UpdateNotification;
use util::channel::ReleaseChannel;
use util::http::HttpClient;
use util_http::HttpClient;
use workspace::Workspace;
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" }
gpui = { path = "../gpui" }
util = { path = "../util" }
util_http = { path = "../util_http" }
rpc = { path = "../rpc" }
settings = { path = "../settings" }
staff_mode = { path = "../staff_mode" }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -29,8 +29,9 @@ use std::{
sync::Arc,
};
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";
actions!(copilot_auth, [SignIn, SignOut]);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -75,9 +75,10 @@ use std::{
};
use terminals::Terminals;
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 _,
};
use util_http::HttpClient;
pub use fs::*;
pub use worktree::*;
@ -681,7 +682,7 @@ impl Project {
) -> ModelHandle<Project> {
let mut languages = LanguageRegistry::test();
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 user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
let project =

View file

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

View file

@ -1,7 +1,5 @@
pub mod channel;
pub mod fs;
pub mod github;
pub mod http;
pub mod paths;
#[cfg(any(test, feature = "test-support"))]
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 futures::AsyncReadExt;
use serde::Deserialize;

View file

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

View file

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

View file

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

View file

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

View file

@ -17,8 +17,8 @@ use std::{
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> {
vec!["-mode=stdio".into()]
}

View file

@ -8,10 +8,10 @@ use smol::fs;
use std::{any::Any, env::consts, ffi::OsString, path::PathBuf};
use util::{
async_iife,
github::{latest_github_release, GitHubLspBinaryVersion},
ResultExt,
};
use util_http::github::{latest_github_release, GitHubLspBinaryVersion};
#[derive(Copy, Clone)]
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 util::{
fs::remove_matching,
github::{latest_github_release, GitHubLspBinaryVersion},
ResultExt,
};
use util_http::github::{latest_github_release, GitHubLspBinaryVersion};
pub struct RustLspAdapter;

View file

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

View file

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