Updated response header
This commit is contained in:
parent
d0fc25c4e1
commit
c870b4bab6
6 changed files with 25 additions and 13 deletions
|
@ -1,5 +1,10 @@
|
|||
# Change Log
|
||||
|
||||
## 4.2.2
|
||||
|
||||
* Added `Date` to response header
|
||||
* Updated `Server: Angel3` response header
|
||||
|
||||
## 4.2.1
|
||||
|
||||
* Updated `package:angel3_container`
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
Angel3 framework is a high-powered HTTP server with support for dependency injection, sophisticated routing, authentication, ORM, graphql etc. It is designed to keep the core minimal but extensible through a series of plugin packages. It won't dictate which features, databases or web templating engine to use. This flexibility enable Angel3 framework to grow with your application as new features can be added to handle the new use cases.
|
||||
|
||||
This package is the core package of [Angel 3](https://github.com/dukefirehawk/angel). To see more details, please refer to the [Developer Guide](https://angel3-docs.dukefirehawk.com).
|
||||
This package is the core package of [Angel3](https://github.com/dukefirehawk/angel). For more information, visit us at [Angel3 Website](https://angel3-framework.web.app).
|
||||
|
||||
## Installation and Setup
|
||||
|
||||
|
|
|
@ -333,7 +333,13 @@ abstract class Driver<
|
|||
return req.close();
|
||||
}
|
||||
|
||||
if (!res.isBuffered) return res.close().then(_cleanup);
|
||||
if (!res.isBuffered) {
|
||||
if (res.isOpen) {
|
||||
return res.close().then(_cleanup);
|
||||
}
|
||||
|
||||
return Future.value();
|
||||
}
|
||||
|
||||
var finalizers = ignoreFinalizers == true
|
||||
? Future.value()
|
||||
|
@ -346,10 +352,10 @@ abstract class Driver<
|
|||
setHeader(response, key, res.headers[key] ?? '');
|
||||
}
|
||||
|
||||
setContentLength(response, res.buffer!.length);
|
||||
setContentLength(response, res.buffer?.length ?? 0);
|
||||
setChunkedEncoding(response, res.chunked ?? true);
|
||||
|
||||
List<int> outputBuffer = res.buffer!.toBytes();
|
||||
var outputBuffer = res.buffer?.toBytes() ?? <int>[];
|
||||
|
||||
if (res.encoders.isNotEmpty) {
|
||||
var allowedEncodings = req.headers
|
||||
|
@ -366,9 +372,9 @@ abstract class Driver<
|
|||
|
||||
if (allowedEncodings != null) {
|
||||
for (var encodingName in allowedEncodings) {
|
||||
Converter<List<int>, List<int>>? encoder;
|
||||
var key = encodingName;
|
||||
|
||||
Converter<List<int>, List<int>>? encoder;
|
||||
if (res.encoders.containsKey(encodingName)) {
|
||||
encoder = res.encoders[encodingName];
|
||||
} else if (encodingName == '*') {
|
||||
|
@ -377,7 +383,8 @@ abstract class Driver<
|
|||
|
||||
if (encoder != null) {
|
||||
setHeader(response, 'content-encoding', key);
|
||||
outputBuffer = res.encoders[key]!.convert(outputBuffer);
|
||||
outputBuffer =
|
||||
res.encoders[key]?.convert(outputBuffer) ?? <int>[];
|
||||
setContentLength(response, outputBuffer.length);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -22,10 +22,8 @@ final RegExp _straySlashes = RegExp(r'(^/+)|(/+$)');
|
|||
abstract class ResponseContext<RawResponse>
|
||||
implements StreamConsumer<List<int>>, StreamSink<List<int>>, StringSink {
|
||||
final Map properties = {};
|
||||
final CaseInsensitiveMap<String> _headers = CaseInsensitiveMap<String>.from({
|
||||
'content-type': 'text/plain',
|
||||
'server': 'angel',
|
||||
});
|
||||
final CaseInsensitiveMap<String> _headers = CaseInsensitiveMap<String>.from(
|
||||
{'content-type': 'text/plain', 'server': 'Angel3'});
|
||||
|
||||
final log = Logger('ResponseContext');
|
||||
|
||||
|
@ -112,14 +110,14 @@ abstract class ResponseContext<RawResponse>
|
|||
///
|
||||
/// Returns `null` if the header is invalidly formatted.
|
||||
int? get contentLength {
|
||||
return int.tryParse(headers['content-length']!);
|
||||
return int.tryParse(headers['content-length'] ?? '-1');
|
||||
}
|
||||
|
||||
/// Gets or sets the content length to send back to a client.
|
||||
///
|
||||
/// If [value] is `null`, then the header will be removed.
|
||||
set contentLength(int? value) {
|
||||
if (value == null) {
|
||||
if (value == null || value == -1) {
|
||||
headers.remove('content-length');
|
||||
} else {
|
||||
headers['content-length'] = value.toString();
|
||||
|
|
|
@ -90,6 +90,8 @@ class HttpResponseContext extends ResponseContext<HttpResponse> {
|
|||
..cookies.addAll(cookies);
|
||||
headers.forEach(rawResponse.headers.set);
|
||||
|
||||
rawResponse.headers.date = DateTime.now();
|
||||
|
||||
if (headers.containsKey('content-length')) {
|
||||
rawResponse.contentLength = int.tryParse(headers['content-length']!) ??
|
||||
rawResponse.contentLength;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel3_framework
|
||||
version: 4.2.1
|
||||
version: 4.2.2
|
||||
description: A high-powered HTTP server extensible framework with dependency injection, routing and much more.
|
||||
homepage: https://angel3-framework.web.app/
|
||||
repository: https://github.com/dukefirehawk/angel/tree/master/packages/framework
|
||||
|
|
Loading…
Reference in a new issue