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

Added support the [http] table #20

Merged
merged 7 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
started on http
  • Loading branch information
ranger-ross committed Aug 11, 2024
commit 8ff3dbf0d67b15e74163dd5eef2fc6f646ac90a0
74 changes: 73 additions & 1 deletion src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ pub struct Config {
#[serde(skip_serializing_if = "FutureIncompatReportConfig::is_none")]
pub future_incompat_report: FutureIncompatReportConfig,
// TODO: cargo-new
// TODO: http
/// The `[http]` table.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#http)
#[serde(default)]
#[serde(skip_serializing_if = "HttpConfig::is_none")]
pub http: HttpConfig,
// TODO: install
/// The `[net]` table.
///
Expand Down Expand Up @@ -438,6 +443,73 @@ pub struct FutureIncompatReportConfig {
pub frequency: Option<Value<Frequency>>,
}

/// The `[http]` table.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#http)
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
#[non_exhaustive]
pub struct HttpConfig {
/// If true, enables debugging of HTTP requests.
/// The debug information can be seen by setting the `CARGO_LOG=network=debug` environment variable
/// (or use `network=trace` for even more information).
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httpdebug)
#[serde(skip_serializing_if = "Option::is_none")]
pub debug: Option<Value<bool>>,
/// Sets an HTTP and HTTPS proxy to use. The format is in libcurl format as in `[protocol://]host[:port]`.
/// If not set, Cargo will also check the http.proxy setting in your global git configuration.
/// If none of those are set, the HTTPS_PROXY or https_proxy environment variables set the proxy for HTTPS requests,
/// and http_proxy sets it for HTTP requests.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httpproxy)
#[serde(skip_serializing_if = "Option::is_none")]
pub proxy: Option<Value<String>>,
/// Sets the timeout for each HTTP request, in seconds.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httptimeout)
#[serde(skip_serializing_if = "Option::is_none")]
pub timeout: Option<Value<u32>>,
/// Path to a Certificate Authority (CA) bundle file, used to verify TLS certificates.
/// If not specified, Cargo attempts to use the system certificates.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httpcainfo)
#[serde(skip_serializing_if = "Option::is_none")]
pub cainfo: Option<Value<String>>,
/// This determines whether or not TLS certificate revocation checks should be performed.
/// This only works on Windows.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httpcheck-revoke)
#[serde(skip_serializing_if = "Option::is_none")]
pub check_revoke: Option<Value<bool>>,
/// This sets the minimum TLS version to use.
/// It takes a string, with one of the possible values of "default", "tlsv1", "tlsv1.0", "tlsv1.1", "tlsv1.2", or "tlsv1.3".
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httpssl-version)
#[serde(skip_serializing_if = "Option::is_none")]
pub ssl_version: Option<Value<String>>, // TODO: Make into an enum?
/// This setting controls timeout behavior for slow connections.
/// If the average transfer speed in bytes per second is below the given value
/// for `http.timeout` seconds (default 30 seconds), then the connection is considered too slow and Cargo will abort and retry.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httplow-speed-limit)
#[serde(skip_serializing_if = "Option::is_none")]
pub low_speed_limit: Option<Value<u32>>,
/// When true, Cargo will attempt to use the HTTP2 protocol with multiplexing.
/// This allows multiple requests to use the same connection, usually improving performance when fetching multiple files.
/// If false, Cargo will use HTTP 1.1 without pipelining.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httpmultiplexing)
#[serde(skip_serializing_if = "Option::is_none")]
pub multiplexing: Option<Value<bool>>,
/// Specifies a custom user-agent header to use.
/// The default if not specified is a string that includes Cargo’s version.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httpuser-agent)
#[serde(skip_serializing_if = "Option::is_none")]
pub user_agent: Option<Value<String>>,
}

/// The `[net]` table.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#net)
Expand Down
91 changes: 90 additions & 1 deletion src/easy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ pub struct Config {
#[serde(skip_serializing_if = "FutureIncompatReportConfig::is_none")]
pub future_incompat_report: FutureIncompatReportConfig,
// TODO: cargo-new
// TODO: http
/// The `[http]` table.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#http)
#[serde(default)]
#[serde(skip_serializing_if = "HttpConfig::is_none")]
pub http: HttpConfig,

// TODO: install
/// The `[net]` table.
///
Expand Down Expand Up @@ -694,6 +700,89 @@ impl FutureIncompatReportConfig {
}
}

/// The `[http]` table.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#http)
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "kebab-case")]
#[non_exhaustive]
pub struct HttpConfig {
/// If true, enables debugging of HTTP requests.
/// The debug information can be seen by setting the `CARGO_LOG=network=debug` environment variable
/// (or use `network=trace` for even more information).
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httpdebug)
#[serde(skip_serializing_if = "Option::is_none")]
pub debug: Option<bool>,
/// Sets an HTTP and HTTPS proxy to use. The format is in libcurl format as in `[protocol://]host[:port]`.
/// If not set, Cargo will also check the http.proxy setting in your global git configuration.
/// If none of those are set, the HTTPS_PROXY or https_proxy environment variables set the proxy for HTTPS requests,
/// and http_proxy sets it for HTTP requests.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httpproxy)
#[serde(skip_serializing_if = "Option::is_none")]
pub proxy: Option<String>,
/// Sets the timeout for each HTTP request, in seconds.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httptimeout)
#[serde(skip_serializing_if = "Option::is_none")]
pub timeout: Option<u32>,
/// Path to a Certificate Authority (CA) bundle file, used to verify TLS certificates.
/// If not specified, Cargo attempts to use the system certificates.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httpcainfo)
#[serde(skip_serializing_if = "Option::is_none")]
pub cainfo: Option<String>,
/// This determines whether or not TLS certificate revocation checks should be performed.
/// This only works on Windows.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httpcheck-revoke)
#[serde(skip_serializing_if = "Option::is_none")]
pub check_revoke: Option<bool>,
/// This sets the minimum TLS version to use.
/// It takes a string, with one of the possible values of "default", "tlsv1", "tlsv1.0", "tlsv1.1", "tlsv1.2", or "tlsv1.3".
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httpssl-version)
#[serde(skip_serializing_if = "Option::is_none")]
pub ssl_version: Option<String>, // TODO: Make into an enum?
/// This setting controls timeout behavior for slow connections.
/// If the average transfer speed in bytes per second is below the given value
/// for `http.timeout` seconds (default 30 seconds), then the connection is considered too slow and Cargo will abort and retry.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httplow-speed-limit)
#[serde(skip_serializing_if = "Option::is_none")]
pub low_speed_limit: Option<u32>,
/// When true, Cargo will attempt to use the HTTP2 protocol with multiplexing.
/// This allows multiple requests to use the same connection, usually improving performance when fetching multiple files.
/// If false, Cargo will use HTTP 1.1 without pipelining.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httpmultiplexing)
#[serde(skip_serializing_if = "Option::is_none")]
pub multiplexing: Option<bool>,
/// Specifies a custom user-agent header to use.
/// The default if not specified is a string that includes Cargo’s version.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#httpuser-agent)
#[serde(skip_serializing_if = "Option::is_none")]
pub user_agent: Option<String>,
}

impl HttpConfig {
fn from_unresolved(de: de::HttpConfig) -> Self {
Self {
debug: de.debug.map(|v| v.val),
proxy: de.proxy.map(|v| v.val),
timeout: de.timeout.map(|v| v.val),
cainfo: de.cainfo.map(|v| v.val),
check_revoke: de.check_revoke.map(|v| v.val),
ssl_version: de.ssl_version.map(|v| v.val),
low_speed_limit: de.low_speed_limit.map(|v| v.val),
multiplexing: de.multiplexing.map(|v| v.val),
user_agent: de.user_agent.map(|v| v.val),
}
}
}

/// The `[net]` table.
///
/// [reference](https://doc.rust-lang.org/nightly/cargo/reference/config.html#net)
Expand Down
12 changes: 12 additions & 0 deletions src/gen/is_none.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.