2.0.0-alpha.19
This commit is contained in:
parent
63c97d9136
commit
3f9e94b12a
4 changed files with 36 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
# 2.0.0-alpha.19
|
||||||
|
* `parseBody` checks for null content type, and throws a `400` if none was given.
|
||||||
|
* Add `ResponseContext.contentLength`.
|
||||||
|
* Update `streamFile` to set content length, and also to work on `HEAD` requests.
|
||||||
|
|
||||||
# 2.0.0-alpha.18
|
# 2.0.0-alpha.18
|
||||||
* Upgrade `http2` dependency.
|
* Upgrade `http2` dependency.
|
||||||
* Upgrade `uuid` dependency.
|
* Upgrade `uuid` dependency.
|
||||||
|
|
|
@ -185,6 +185,10 @@ abstract class RequestContext<RawRequest> {
|
||||||
|
|
||||||
/// Manually parses the request body, if it has not already been parsed.
|
/// Manually parses the request body, if it has not already been parsed.
|
||||||
Future<void> parseBody({Encoding encoding: utf8}) async {
|
Future<void> parseBody({Encoding encoding: utf8}) async {
|
||||||
|
if (contentType == null) {
|
||||||
|
throw FormatException('Missing "content-type" header.');
|
||||||
|
}
|
||||||
|
|
||||||
if (!_hasParsedBody) {
|
if (!_hasParsedBody) {
|
||||||
_hasParsedBody = true;
|
_hasParsedBody = true;
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ abstract class ResponseContext<RawResponse>
|
||||||
/// This response's status code.
|
/// This response's status code.
|
||||||
int get statusCode => _statusCode;
|
int get statusCode => _statusCode;
|
||||||
|
|
||||||
void set statusCode(int value) {
|
set statusCode(int value) {
|
||||||
if (!isOpen)
|
if (!isOpen)
|
||||||
throw closed();
|
throw closed();
|
||||||
else
|
else
|
||||||
|
@ -104,6 +104,23 @@ abstract class ResponseContext<RawResponse>
|
||||||
/// open indefinitely.
|
/// open indefinitely.
|
||||||
FutureOr<RawResponse> detach();
|
FutureOr<RawResponse> detach();
|
||||||
|
|
||||||
|
/// Gets or sets the content length to send back to a client.
|
||||||
|
///
|
||||||
|
/// Returns `null` if the header is invalidly formatted.
|
||||||
|
int get contentLength {
|
||||||
|
return int.tryParse(headers['content-length']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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)
|
||||||
|
headers.remove('content-length');
|
||||||
|
else
|
||||||
|
headers['content-length'] = value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets or sets the content type to send back to a client.
|
/// Gets or sets the content type to send back to a client.
|
||||||
MediaType get contentType {
|
MediaType get contentType {
|
||||||
try {
|
try {
|
||||||
|
@ -114,7 +131,7 @@ abstract class ResponseContext<RawResponse>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets or sets the content type to send back to a client.
|
/// Gets or sets the content type to send back to a client.
|
||||||
void set contentType(MediaType value) {
|
set contentType(MediaType value) {
|
||||||
headers['content-type'] = value.toString();
|
headers['content-type'] = value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,12 +306,17 @@ abstract class ResponseContext<RawResponse>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Streams a file to this response.
|
/// Streams a file to this response.
|
||||||
Future streamFile(File file) {
|
///
|
||||||
|
/// `HEAD` responses will not actually write data.
|
||||||
|
Future streamFile(File file) async {
|
||||||
if (!isOpen) throw closed();
|
if (!isOpen) throw closed();
|
||||||
var mimeType = app.mimeTypeResolver.lookup(file.path);
|
var mimeType = app.mimeTypeResolver.lookup(file.path);
|
||||||
|
contentLength = await file.length();
|
||||||
contentType = mimeType == null
|
contentType = mimeType == null
|
||||||
? new MediaType('application', 'octet-stream')
|
? new MediaType('application', 'octet-stream')
|
||||||
: MediaType.parse(mimeType);
|
: MediaType.parse(mimeType);
|
||||||
|
|
||||||
|
if (correspondingRequest.method != 'HEAD')
|
||||||
return file.openRead().pipe(this);
|
return file.openRead().pipe(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_framework
|
name: angel_framework
|
||||||
version: 2.0.0-alpha.18
|
version: 2.0.0-alpha.19
|
||||||
description: A high-powered HTTP server with dependency injection, routing and much more.
|
description: A high-powered HTTP server with dependency injection, routing and much more.
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/angel_framework
|
homepage: https://github.com/angel-dart/angel_framework
|
||||||
|
|
Loading…
Reference in a new issue