HttpConfig class

HTTP 配置类,用于存储 HTTP 请求的配置信息

@example

// 创建默认配置
final config = HttpConfig();

// 创建自定义配置
final custom = HttpConfig(
  connectTimeout: const Duration(seconds: 5),
  retry: true,
  retryCount: 3,
);

// 基于现有配置创建
final modified = custom.copyWith(retryCount: 5);

Constructors

HttpConfig({Duration? connectTimeout, Duration? receiveTimeout, bool? retry, int? retryCount, bool? enableCertificateValidation, Map<String, String>? securityHeaders})
创建 HTTP 配置
HttpConfig.fastTimeout()
创建快速超时配置(适合局域网或内部服务)
factory
HttpConfig.unsafe()
创建不安全配置(仅用于测试环境)
factory
HttpConfig.withRetry({int count = 3})
创建带重试机制的配置
factory

Properties

connectTimeout → Duration
连接超时时间,默认 10 秒
final
enableCertificateValidation → bool
是否启用 HTTPS 证书验证,默认 true
final
hashCode → int
The hash code for this object.
no setterinherited
receiveTimeout → Duration
接收超时时间,默认 50 秒
final
retry → bool
是否启用重试,默认 false
final
retryCount → int
重试次数,默认 3 次
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
securityHeaders → Map<String, String>
安全响应头部配置(不可变)
final

Methods

addSecurityHeader(String key, String value) → HttpConfig
添加安全响应头部并返回新配置
copyWith({Duration? connectTimeout, Duration? receiveTimeout, bool? retry, int? retryCount, bool? enableCertificateValidation, Map<String, String>? securityHeaders}) → HttpConfig
复制配置并返回新实例
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited