feat: sync httpdns sdk/platform updates without large binaries

This commit is contained in:
robin
2026-03-04 17:59:14 +08:00
parent 853897a6f8
commit 532891fad0
700 changed files with 6096 additions and 2712 deletions

View File

@@ -0,0 +1,84 @@
// Internal helpers for NW HTTP client
#import <Foundation/Foundation.h>
#import <Network/Network.h>
#import <Security/SecTrust.h>
#import "HttpdnsNWHTTPClient.h"
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, HttpdnsHTTPHeaderParseResult) {
HttpdnsHTTPHeaderParseResultIncomplete = 0,
HttpdnsHTTPHeaderParseResultSuccess,
HttpdnsHTTPHeaderParseResultError,
};
typedef NS_ENUM(NSInteger, HttpdnsHTTPChunkParseResult) {
HttpdnsHTTPChunkParseResultIncomplete = 0,
HttpdnsHTTPChunkParseResultSuccess,
HttpdnsHTTPChunkParseResultError,
};
@interface HttpdnsNWHTTPClient (Internal)
// TLS 验证
- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust forDomain:(NSString *)domain;
// HTTP 头部解析
- (HttpdnsHTTPHeaderParseResult)tryParseHTTPHeadersInData:(NSData *)data
headerEndIndex:(nullable NSUInteger *)headerEndIndex
statusCode:(nullable NSInteger *)statusCode
headers:(NSDictionary<NSString *, NSString *> *__autoreleasing _Nullable * _Nullable)headers
error:(NSError * _Nullable * _Nullable)error;
// Chunked 编码检<E7A081><E6A380>?
- (HttpdnsHTTPChunkParseResult)checkChunkedBodyCompletionInData:(NSData *)data
headerEndIndex:(NSUInteger)headerEndIndex
error:(NSError * _Nullable * _Nullable)error;
// Chunked 编码解码
- (nullable NSData *)decodeChunkedBody:(NSData *)bodyData error:(NSError * _Nullable * _Nullable)error;
// 完整 HTTP 响应解析
- (BOOL)parseHTTPResponseData:(NSData *)data
statusCode:(nullable NSInteger *)statusCode
headers:(NSDictionary<NSString *, NSString *> *__autoreleasing _Nullable * _Nullable)headers
body:(NSData *__autoreleasing _Nullable * _Nullable)body
error:(NSError * _Nullable * _Nullable)error;
// HTTP 请求构建
- (NSString *)buildHTTPRequestStringWithURL:(NSURL *)url userAgent:(NSString *)userAgent;
// 连接<E8BF9E><E68EA5>?key 生成
- (NSString *)connectionPoolKeyForHost:(NSString *)host port:(NSString *)port useTLS:(BOOL)useTLS;
// 错误转换
+ (NSError *)errorFromNWError:(nw_error_t)nwError description:(NSString *)description;
@end
#if DEBUG
// 测试专用连接池检<E6B1A0><E6A380>?API
@interface HttpdnsNWHTTPClient (TestInspection)
// 获取指定 pool key 的连接数<E68EA5><E695B0>?
- (NSUInteger)connectionPoolCountForKey:(NSString *)key;
// 获取所有连接池 keys
- (NSArray<NSString *> *)allConnectionPoolKeys;
// 获取连接池总连接数
- (NSUInteger)totalConnectionCount;
// 连接创建计数(用于验证连接复用)
@property (atomic, assign) NSUInteger connectionCreationCount;
// 连接复用计数(用于验证连接复用)
@property (atomic, assign) NSUInteger connectionReuseCount;
// 重置统计计数器每个测试开始前调用<E8B083><E794A8>?
- (void)resetPoolStatistics;
@end
#endif
NS_ASSUME_NONNULL_END