Skip to content
Merged
34 changes: 16 additions & 18 deletions examples/emulation_firefox.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use http::{HeaderMap, HeaderValue, header};
use wreq::{
Client, EmulationProvider, OriginalHeaders,
http1::Http1Config,
Client, Emulation, OriginalHeaders,
http1::Http1Options,
http2::{
Http2Config, Priorities, Priority, PseudoId, PseudoOrder, SettingId, SettingsOrder,
Http2Options, Priorities, Priority, PseudoId, PseudoOrder, SettingId, SettingsOrder,
StreamDependency, StreamId,
},
tls::{AlpnProtocol, CertificateCompressionAlgorithm, ExtensionType, TlsConfig, TlsVersion},
tls::{AlpnProtocol, CertificateCompressionAlgorithm, ExtensionType, TlsOptions, TlsVersion},
};

macro_rules! join {
Expand All @@ -21,8 +21,8 @@ async fn main() -> wreq::Result<()> {
.with_max_level(tracing::Level::TRACE)
.init();

// TLS config
let tls = TlsConfig::builder()
// TLS options config
let tls = TlsOptions::builder()
.curves_list(join!(
":",
"X25519",
Expand Down Expand Up @@ -78,7 +78,7 @@ async fn main() -> wreq::Result<()> {
CertificateCompressionAlgorithm::BROTLI,
CertificateCompressionAlgorithm::ZSTD,
])
.alpn_protos(&[AlpnProtocol::HTTP2, AlpnProtocol::HTTP1])
.alpn_protocols(&[AlpnProtocol::HTTP2, AlpnProtocol::HTTP1])
.record_size_limit(0x4001)
.pre_shared_key(true)
.enable_ech_grease(true)
Expand Down Expand Up @@ -107,13 +107,13 @@ async fn main() -> wreq::Result<()> {
])
.build();

// HTTP/1 config
let http1 = Http1Config::builder()
// HTTP/1 options config
let http1 = Http1Options::builder()
.allow_obsolete_multiline_headers_in_responses(true)
.max_headers(100)
.build();

// HTTP/2 config
// HTTP/2 options config
let http2 = {
// HTTP/2 headers frame pseudo-header order
let headers_pseudo_order = PseudoOrder::builder()
Expand Down Expand Up @@ -169,7 +169,7 @@ async fn main() -> wreq::Result<()> {
])
.build();

Http2Config::builder()
Http2Options::builder()
.initial_stream_id(15)
.header_table_size(65536)
.initial_stream_window_size(131072)
Expand Down Expand Up @@ -198,7 +198,6 @@ async fn main() -> wreq::Result<()> {
headers
};

// Original headers
// The headers keep the original case and order
let original_headers = {
let mut original_headers = OriginalHeaders::new();
Expand All @@ -210,13 +209,12 @@ async fn main() -> wreq::Result<()> {
original_headers
};

// Create emulation provider with all configurations
// This provider encapsulates TLS, HTTP/1, HTTP/2, default headers, and original headers
let emulation = EmulationProvider::builder()
.tls_config(tls)
.http1_config(http1)
.http2_config(http2)
.default_headers(headers)
let emulation = Emulation::builder()
.tls_options(tls)
.http1_options(http1)
.http2_options(http2)
.headers(headers)
.original_headers(original_headers)
.build();

Expand Down
25 changes: 12 additions & 13 deletions examples/emulation_twitter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use http::{HeaderMap, HeaderValue, header};
use wreq::{
Client, EmulationProvider, OriginalHeaders,
http2::{Http2Config, PseudoId, PseudoOrder},
tls::{AlpnProtocol, TlsConfig, TlsVersion},
Client, Emulation, OriginalHeaders,
http2::{Http2Options, PseudoId, PseudoOrder},
tls::{AlpnProtocol, TlsOptions, TlsVersion},
};

macro_rules! join {
Expand All @@ -17,8 +17,8 @@ async fn main() -> wreq::Result<()> {
.with_max_level(tracing::Level::TRACE)
.init();

// TLS config
let tls = TlsConfig::builder()
// TLS options config
let tls = TlsOptions::builder()
.enable_ocsp_stapling(true)
.curves_list(join!(":", "X25519", "P-256", "P-384"))
.cipher_list(join!(
Expand All @@ -45,13 +45,13 @@ async fn main() -> wreq::Result<()> {
"rsa_pkcs1_sha512",
"rsa_pkcs1_sha1"
))
.alpn_protos(&[AlpnProtocol::HTTP2, AlpnProtocol::HTTP1])
.alpn_protocols(&[AlpnProtocol::HTTP2, AlpnProtocol::HTTP1])
.min_tls_version(TlsVersion::TLS_1_2)
.max_tls_version(TlsVersion::TLS_1_3)
.build();

// HTTP/2 config
let http2 = Http2Config::builder()
// HTTP/2 options config
let http2 = Http2Options::builder()
.initial_stream_id(3)
.initial_stream_window_size(16777216)
.initial_connection_window_size(16711681 + 65535)
Expand Down Expand Up @@ -97,12 +97,11 @@ async fn main() -> wreq::Result<()> {
original_headers
};

// Create emulation provider with all configurations
// This provider encapsulates TLS, HTTP/1, HTTP/2, default headers, and original headers
let emulation = EmulationProvider::builder()
.tls_config(tls)
.http2_config(http2)
.default_headers(headers)
let emulation = Emulation::builder()
.tls_options(tls)
.http2_options(http2)
.headers(headers)
.original_headers(original_headers)
.build();

Expand Down
19 changes: 11 additions & 8 deletions examples/http1_recv_case_sensitive_headers.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use wreq::{OriginalHeaders, http1::Http1Config};
use wreq::{Client, OriginalHeaders, http1::Http1Options};

#[tokio::main]
async fn main() -> wreq::Result<()> {
let client = wreq::Client::builder()
.configure_http1(
Http1Config::builder()
.preserve_header_case(true)
.http09_responses(true)
.build(),
)
// Enable case-sensitive header handling in HTTP/1
let http1_options = Http1Options::builder()
.preserve_header_case(true)
.http09_responses(true)
.max_headers(100)
.build();

// Create a client with the HTTP/1 options
let client = Client::builder()
.emulation(http1_options)
.http1_only()
.build()?;

Expand Down
6 changes: 3 additions & 3 deletions examples/http1_send_case_sensitive_headers.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use http::{HeaderMap, HeaderName, HeaderValue};
use wreq::OriginalHeaders;
use wreq::{Client, OriginalHeaders};

#[tokio::main]
async fn main() -> wreq::Result<()> {
let client = wreq::Client::builder()
let client = Client::builder()
.cert_verification(false)
.http1_only()
.build()?;
Expand All @@ -12,7 +12,7 @@ async fn main() -> wreq::Result<()> {
let mut original_headers = OriginalHeaders::new();
original_headers.insert("Host");
original_headers.insert("X-custom-Header1");
original_headers.extend(["x-Custom-Header2"]);
original_headers.insert("x-Custom-Header2");
original_headers.insert(HeaderName::from_static("x-custom-header3"));

// Use the API you're already familiar with
Expand Down
2 changes: 1 addition & 1 deletion examples/http1_websocket.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;

use futures_util::{SinkExt, StreamExt, TryStreamExt};
use wreq::{Client, header, websocket::Message};
use wreq::{Client, header, ws::Message};

#[tokio::main]
async fn main() -> wreq::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion examples/http2_websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use std::time::Duration;

use futures_util::{SinkExt, StreamExt, TryStreamExt};
use wreq::{Client, header, websocket::Message};
use wreq::{Client, header, ws::Message};

#[tokio::main]
async fn main() -> wreq::Result<()> {
Expand Down
26 changes: 12 additions & 14 deletions examples/request_with_emulation.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use http::{HeaderMap, HeaderValue, header};
use wreq::{
Client, EmulationProvider, OriginalHeaders,
http2::{Http2Config, PseudoId, PseudoOrder},
tls::{AlpnProtocol, TlsConfig, TlsVersion},
Client, Emulation, OriginalHeaders,
http2::{Http2Options, PseudoId, PseudoOrder},
tls::{AlpnProtocol, TlsOptions, TlsVersion},
};

macro_rules! join {
Expand All @@ -17,8 +17,8 @@ async fn main() -> wreq::Result<()> {
.with_max_level(tracing::Level::TRACE)
.init();

// TLS config
let tls = TlsConfig::builder()
// TLS options config
let tls = TlsOptions::builder()
.enable_ocsp_stapling(true)
.curves_list(join!(":", "X25519", "P-256", "P-384"))
.cipher_list(join!(
Expand All @@ -45,13 +45,13 @@ async fn main() -> wreq::Result<()> {
"rsa_pkcs1_sha512",
"rsa_pkcs1_sha1"
))
.alpn_protos(&[AlpnProtocol::HTTP2, AlpnProtocol::HTTP1])
.alpn_protocols(&[AlpnProtocol::HTTP2, AlpnProtocol::HTTP1])
.min_tls_version(TlsVersion::TLS_1_2)
.max_tls_version(TlsVersion::TLS_1_3)
.build();

// HTTP/2 config
let http2 = Http2Config::builder()
// HTTP/2 options config
let http2 = Http2Options::builder()
.initial_stream_id(3)
.initial_stream_window_size(16777216)
.initial_connection_window_size(16711681 + 65535)
Expand Down Expand Up @@ -85,7 +85,6 @@ async fn main() -> wreq::Result<()> {
headers
};

// Original headers
// The headers keep the original case and order
let original_headers = {
let mut original_headers = OriginalHeaders::new();
Expand All @@ -97,12 +96,11 @@ async fn main() -> wreq::Result<()> {
original_headers
};

// Create emulation provider with all configurations
// This provider encapsulates TLS, HTTP/1, HTTP/2, default headers, and original headers
let emulation = EmulationProvider::builder()
.tls_config(tls)
.http2_config(http2)
.default_headers(headers)
let emulation = Emulation::builder()
.tls_options(tls)
.http2_options(http2)
.headers(headers)
.original_headers(original_headers)
.build();

Expand Down
29 changes: 0 additions & 29 deletions src/client/client/macros.rs

This file was deleted.

Loading
Loading