Skip to main content

orinium_browser/platform/network/
config.rs

1//! ネットワーク層の設定。タイムアウト、キャッシュ、ユーザーエージェント。
2
3use std::time::Duration;
4
5use serde::{Deserialize, Serialize};
6
7/// ネットワーク層全体の設定
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct NetworkConfig {
10    /// User-Agent文字列
11    pub user_agent: String,
12
13    /// タイムアウト設定
14    pub connect_timeout: Duration,
15    pub read_timeout: Duration,
16
17    /// キャッシュを有効化するか
18    pub enable_cache: bool,
19
20    /// Cookie管理を有効化するか
21    pub enable_cookies: bool,
22
23    /// TLS証明書の検証を有効化するか
24    pub verify_tls: bool,
25
26    /// プロキシ設定
27    pub proxies: Vec<ProxyConfig>,
28
29    /// 最大同時接続数
30    pub max_connections: usize,
31
32    /// リダイレクトを自動フォローするか
33    pub follow_redirects: bool,
34
35    /// WebSocketを有効化するか
36    pub enable_websocket: bool,
37}
38
39#[allow(dead_code)]
40#[derive(Debug, Clone)]
41pub enum ProxyType {
42    Http,
43    Https,
44    Socks5,
45}
46
47#[allow(dead_code)]
48#[derive(Debug, Clone, Deserialize, Serialize)]
49pub struct ProxyConfig {
50    pub proxy_type: String,
51    pub host: String,
52    pub port: u16,
53    pub username: Option<String>,
54    pub password: Option<String>,
55}
56
57#[allow(dead_code)]
58#[derive(Debug, Clone, Default)]
59pub struct ProxySettings {
60    pub proxies: Vec<ProxyConfig>, // 複数種類を保持できる
61}
62
63impl Default for NetworkConfig {
64    fn default() -> Self {
65        Self {
66            user_agent: String::from(
67                "OrinionBrowser/0.1 (+https://github.com/Orinas-github/Orinium-browser)",
68            ),
69            connect_timeout: Duration::from_secs(10),
70            read_timeout: Duration::from_secs(30),
71            enable_cache: true,
72            enable_cookies: true,
73            verify_tls: true,
74            proxies: vec![],
75            max_connections: 100,
76            follow_redirects: true,
77            enable_websocket: true,
78        }
79    }
80}