chunked encoding content length

This commit is contained in:
wanghongenpin
2024-02-19 18:44:30 +08:00
parent 666c694335
commit 98d27de6e6
10 changed files with 28 additions and 22 deletions

View File

@@ -77,7 +77,7 @@ class Channel {
remotePort = _socket.remotePort;
///返回此channel的全局唯一标识符。
String get id => _id.toRadixString(16);
String get id => _id.toRadixString(36);
Socket get socket => _socket;

View File

@@ -29,7 +29,6 @@ import '../../utils/compress.dart';
import 'http.dart';
import 'http_headers.dart';
class ParserException implements Exception {
final String message;
final String? source;
@@ -162,11 +161,12 @@ abstract class HttpCodec<T extends HttpMessage> implements Codec<T> {
}
//请求头
bool isChunked = message.headers.isChunked;
message.headers.remove(HttpHeaders.TRANSFER_ENCODING);
if (body != null && body.isNotEmpty) {
if (body != null && (body.isNotEmpty || isChunked)) {
message.headers.contentLength = body.length;
} else if (message.contentLength != 0){
} else if (message.contentLength != 0) {
message.headers.remove(HttpHeaders.CONTENT_LENGTH);
}

View File

@@ -51,7 +51,7 @@ abstract class HttpMessage {
List<int>? body;
String? remoteAddress;
String requestId = (DateTime.now().millisecondsSinceEpoch + Random().nextInt(99999)).toRadixString(16);
String requestId = (DateTime.now().millisecondsSinceEpoch + Random().nextInt(99999)).toRadixString(36);
int? streamId; // http2 streamId
HttpMessage(this.protocolVersion);
@@ -266,6 +266,7 @@ enum HttpMethod {
trace("TRACE"),
connect("CONNECT"),
propfind("PROPFIND"),
report("REPORT"),
;
final String name;
@@ -280,6 +281,10 @@ enum HttpMethod {
rethrow;
}
}
static List<HttpMethod> methods() {
return values.where((method) => method != HttpMethod.propfind && method != HttpMethod.report).toList();
}
}
///HTTP响应状态。

View File

@@ -85,9 +85,10 @@ class HttpHeaders {
return _headers[originalHeaderName];
}
void remove(String name) {
bool remove(String name) {
var originalHeaderName = _originalHeaderNames.remove(name.toLowerCase());
_headers.remove(originalHeaderName);
return originalHeaderName != null;
}
int? getInt(String name) {