@@ -8,22 +8,22 @@ import 'package:http_parser/http_parser.dart';
8
8
import 'urls.dart' ;
9
9
import 'xdnmb.dart' ;
10
10
11
- /// 将cookie列表转化为cookie值
11
+ /// 将 cookie 列表转化为 cookie 值
12
12
String _toCookies (Iterable <String > cookies) => cookies.join ('; ' );
13
13
14
- /// [Response] 的扩展
14
+ /// [Response] 的扩展
15
15
extension ResponseExtension on Response {
16
- /// 返回utf8编码的 [body] ,不用[body] 是因为X岛返回的header可能不包含编码信息 ,
16
+ /// 返回 utf8 编码的 [body] ,不用 [body] 是因为 X 岛返回的 header 可能不包含编码信息 ,
17
17
/// 这样解码会出错
18
18
String get utf8Body => utf8.decode (bodyBytes);
19
19
}
20
20
21
- /// HTTP状态异常
21
+ /// HTTP 状态异常
22
22
class HttpStatusException implements Exception {
23
23
/// 状态码
24
24
final int statusCode;
25
25
26
- /// 构造[HttpStatusException]
26
+ /// 构造 [HttpStatusException]
27
27
const HttpStatusException (this .statusCode);
28
28
29
29
@override
@@ -39,14 +39,14 @@ class HttpStatusException implements Exception {
39
39
int get hashCode => statusCode.hashCode;
40
40
}
41
41
42
- /// multipart的实现
42
+ /// multipart 的实现
43
43
class Multipart extends MultipartRequest {
44
- /// 构造[Multipart]
44
+ /// 构造 [Multipart]
45
45
///
46
- /// [url] 为请求链接
46
+ /// [url] 为请求链接
47
47
Multipart (Uri url) : super ('POST' , url);
48
48
49
- /// 添加字段,值为[value] 的字符串表达
49
+ /// 添加字段,值为 [value] 的字符串表达
50
50
void add (String field, Object value) => fields[field] = value.toString ();
51
51
52
52
/// 添加字段
@@ -63,7 +63,7 @@ class Multipart extends MultipartRequest {
63
63
);
64
64
}
65
65
66
- /// HTTP client的实现
66
+ /// HTTP client 的实现
67
67
class Client extends IOClient {
68
68
/// 默认连接超时时长
69
69
static const Duration defaultConnectionTimeout = Duration (seconds: 15 );
@@ -74,19 +74,19 @@ class Client extends IOClient {
74
74
/// 默认`User-Agent`
75
75
static const String _defaultUserAgent = 'xdnmb' ;
76
76
77
- /// X岛的PHP session ID
77
+ /// X 岛的 PHP session ID
78
78
String ? xdnmbPhpSessionId;
79
79
80
- /// X岛备用API的PHP session ID
80
+ /// X 岛备用 API 的 PHP session ID
81
81
String ? _xdnmbBackupApiPhpSessionId;
82
82
83
- /// 构造[Client]
83
+ /// 构造 [Client]
84
84
///
85
- /// [client] 为 [HttpClient]
85
+ /// [client] 为 [HttpClient]
86
86
///
87
- /// [connectionTimeout] 为连接超时时长,默认为15秒
87
+ /// [connectionTimeout] 为连接超时时长,默认为 15 秒
88
88
///
89
- /// [idleTimeout] 为连接空闲超时时长,默认为90秒
89
+ /// [idleTimeout] 为连接空闲超时时长,默认为 90 秒
90
90
Client (
91
91
{HttpClient ? client,
92
92
Duration ? connectionTimeout,
@@ -97,15 +97,15 @@ class Client extends IOClient {
97
97
..idleTimeout = idleTimeout ?? _defaultIdleTimeout
98
98
..userAgent = userAgent ?? _defaultUserAgent);
99
99
100
- /// [xdnmbPhpSessionId] 有效
100
+ /// [xdnmbPhpSessionId] 有效
101
101
bool _xdnmbPhpSessionIdIsValid (Uri url) =>
102
102
xdnmbPhpSessionId != null && XdnmbUrls ().isBaseUrl (url);
103
103
104
- /// [_xdnmbBackupApiPhpSessionId] 有效
104
+ /// [_xdnmbBackupApiPhpSessionId] 有效
105
105
bool _xdnmbBackupApiPhpSessionIdIsValid (Uri url) =>
106
106
_xdnmbBackupApiPhpSessionId != null && XdnmbUrls ().isBackupApiUrl (url);
107
107
108
- /// 返回cookie头
108
+ /// 返回 cookie 头
109
109
Map <String , String >? _cookieHeasers (Uri url, String ? cookie) =>
110
110
(cookie != null ||
111
111
_xdnmbPhpSessionIdIsValid (url) ||
@@ -120,15 +120,15 @@ class Client extends IOClient {
120
120
}
121
121
: null ;
122
122
123
- /// GET请求
123
+ /// GET 请求
124
124
Future <Response > xGet (Uri url, [String ? cookie]) async {
125
125
final response = await this .get (url, headers: _cookieHeasers (url, cookie));
126
126
_checkStatusCode (response);
127
127
128
128
return response;
129
129
}
130
130
131
- /// POST form请求
131
+ /// POST form 请求
132
132
Future <Response > xPostForm (Uri url, Map <String , String >? form,
133
133
[String ? cookie]) async {
134
134
final response =
@@ -138,7 +138,7 @@ class Client extends IOClient {
138
138
return response;
139
139
}
140
140
141
- /// POST multipart请求
141
+ /// POST multipart 请求
142
142
Future <Response > xPostMultipart (Multipart multipart, [String ? cookie]) async {
143
143
if (cookie != null ||
144
144
_xdnmbPhpSessionIdIsValid (multipart.url) ||
@@ -161,7 +161,7 @@ class Client extends IOClient {
161
161
Future <IOStreamedResponse > send (BaseRequest request) async {
162
162
final response = await super .send (request);
163
163
164
- // 获取xdnmbPhpSessionId和_xdnmbBackupApiPhpSessionId
164
+ // 获取 xdnmbPhpSessionId 和_xdnmbBackupApiPhpSessionId
165
165
final setCookie = response.headers[HttpHeaders .setCookieHeader];
166
166
if (setCookie != null ) {
167
167
final cookies = setCookie.split (RegExp (r',(?! )' ));
@@ -177,7 +177,7 @@ class Client extends IOClient {
177
177
}
178
178
}
179
179
} catch (e) {
180
- print ('解析set-cookie出现错误 :$e ' );
180
+ print ('解析 set-cookie 出现错误 :$e ' );
181
181
}
182
182
}
183
183
}
@@ -186,7 +186,7 @@ class Client extends IOClient {
186
186
}
187
187
}
188
188
189
- /// 检查HTTP状态码
189
+ /// 检查 HTTP 状态码
190
190
void _checkStatusCode (Response response) {
191
191
if (response.statusCode != HttpStatus .ok) {
192
192
throw HttpStatusException (response.statusCode);
0 commit comments