73
This commit is contained in:
parent
9683e97603
commit
94886bca13
3 changed files with 16 additions and 17 deletions
|
@ -1,6 +1,6 @@
|
||||||
# angel_framework
|
# angel_framework
|
||||||
|
|
||||||
[![pub 1.0.0-dev.72](https://img.shields.io/badge/pub-1.0.0--dev.72-red.svg)](https://pub.dartlang.org/packages/angel_framework)
|
[![pub 1.0.0-dev.73](https://img.shields.io/badge/pub-1.0.0--dev.73-red.svg)](https://pub.dartlang.org/packages/angel_framework)
|
||||||
[![build status](https://travis-ci.org/angel-dart/framework.svg)](https://travis-ci.org/angel-dart/framework)
|
[![build status](https://travis-ci.org/angel-dart/framework.svg)](https://travis-ci.org/angel-dart/framework)
|
||||||
|
|
||||||
A high-powered HTTP server with support for dependency injection, sophisticated routing and more.
|
A high-powered HTTP server with support for dependency injection, sophisticated routing and more.
|
||||||
|
|
|
@ -34,12 +34,11 @@ class ResponseContext extends Extensible {
|
||||||
final List<Cookie> cookies = [];
|
final List<Cookie> cookies = [];
|
||||||
|
|
||||||
/// Headers that will be sent to the user.
|
/// Headers that will be sent to the user.
|
||||||
///
|
|
||||||
/// If the response is closed, then this getter will return an immutable `Map`.
|
|
||||||
Map<String, String> get headers {
|
Map<String, String> get headers {
|
||||||
if (!_isOpen)
|
/// If the response is closed, then this getter will return an immutable `Map`.
|
||||||
|
/*if (!_isOpen)
|
||||||
return new Map<String, String>.unmodifiable(_headers);
|
return new Map<String, String>.unmodifiable(_headers);
|
||||||
else
|
else*/
|
||||||
return _headers;
|
return _headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +112,7 @@ class ResponseContext extends Extensible {
|
||||||
|
|
||||||
/// Sends a download as a response.
|
/// Sends a download as a response.
|
||||||
download(File file, {String filename}) async {
|
download(File file, {String filename}) async {
|
||||||
if (!_isOpen) throw _closed();
|
// if (!_isOpen) throw _closed();
|
||||||
|
|
||||||
headers["Content-Disposition"] =
|
headers["Content-Disposition"] =
|
||||||
'attachment; filename="${filename ?? file.path}"';
|
'attachment; filename="${filename ?? file.path}"';
|
||||||
|
@ -151,7 +150,7 @@ class ResponseContext extends Extensible {
|
||||||
|
|
||||||
/// Returns a JSONP response.
|
/// Returns a JSONP response.
|
||||||
void jsonp(value, {String callbackName: "callback", contentType}) {
|
void jsonp(value, {String callbackName: "callback", contentType}) {
|
||||||
if (!_isOpen) throw _closed();
|
// if (!_isOpen) throw _closed();
|
||||||
write("$callbackName(${serializer(value)})");
|
write("$callbackName(${serializer(value)})");
|
||||||
|
|
||||||
if (contentType != null) {
|
if (contentType != null) {
|
||||||
|
@ -167,7 +166,7 @@ class ResponseContext extends Extensible {
|
||||||
|
|
||||||
/// Renders a view to the response stream, and closes the response.
|
/// Renders a view to the response stream, and closes the response.
|
||||||
Future render(String view, [Map data]) async {
|
Future render(String view, [Map data]) async {
|
||||||
if (!_isOpen) throw _closed();
|
// if (!_isOpen) throw _closed();
|
||||||
write(await app.viewGenerator(view, data));
|
write(await app.viewGenerator(view, data));
|
||||||
headers[HttpHeaders.CONTENT_TYPE] = ContentType.HTML.toString();
|
headers[HttpHeaders.CONTENT_TYPE] = ContentType.HTML.toString();
|
||||||
end();
|
end();
|
||||||
|
@ -181,7 +180,7 @@ class ResponseContext extends Extensible {
|
||||||
///
|
///
|
||||||
/// See [Router]#navigate for more. :)
|
/// See [Router]#navigate for more. :)
|
||||||
void redirect(url, {bool absolute: true, int code: 302}) {
|
void redirect(url, {bool absolute: true, int code: 302}) {
|
||||||
if (!_isOpen) throw _closed();
|
// if (!_isOpen) throw _closed();
|
||||||
headers[HttpHeaders.LOCATION] =
|
headers[HttpHeaders.LOCATION] =
|
||||||
url is String ? url : app.navigate(url, absolute: absolute);
|
url is String ? url : app.navigate(url, absolute: absolute);
|
||||||
statusCode = code ?? 302;
|
statusCode = code ?? 302;
|
||||||
|
@ -207,7 +206,7 @@ class ResponseContext extends Extensible {
|
||||||
|
|
||||||
/// Redirects to the given named [Route].
|
/// Redirects to the given named [Route].
|
||||||
void redirectTo(String name, [Map params, int code]) {
|
void redirectTo(String name, [Map params, int code]) {
|
||||||
if (!_isOpen) throw _closed();
|
// if (!_isOpen) throw _closed();
|
||||||
Route _findRoute(Router r) {
|
Route _findRoute(Router r) {
|
||||||
for (Route route in r.routes) {
|
for (Route route in r.routes) {
|
||||||
if (route is SymlinkRoute) {
|
if (route is SymlinkRoute) {
|
||||||
|
@ -232,7 +231,7 @@ class ResponseContext extends Extensible {
|
||||||
|
|
||||||
/// Redirects to the given [Controller] action.
|
/// Redirects to the given [Controller] action.
|
||||||
void redirectToAction(String action, [Map params, int code]) {
|
void redirectToAction(String action, [Map params, int code]) {
|
||||||
if (!_isOpen) throw _closed();
|
// if (!_isOpen) throw _closed();
|
||||||
// UserController@show
|
// UserController@show
|
||||||
List<String> split = action.split("@");
|
List<String> split = action.split("@");
|
||||||
|
|
||||||
|
@ -262,7 +261,7 @@ class ResponseContext extends Extensible {
|
||||||
/// Copies a file's contents into the response buffer.
|
/// Copies a file's contents into the response buffer.
|
||||||
Future sendFile(File file,
|
Future sendFile(File file,
|
||||||
{int chunkSize, int sleepMs: 0, bool resumable: true}) async {
|
{int chunkSize, int sleepMs: 0, bool resumable: true}) async {
|
||||||
if (!_isOpen) throw _closed();
|
// if (!_isOpen) throw _closed();
|
||||||
|
|
||||||
headers[HttpHeaders.CONTENT_TYPE] = lookupMimeType(file.path);
|
headers[HttpHeaders.CONTENT_TYPE] = lookupMimeType(file.path);
|
||||||
buffer.add(await file.readAsBytes());
|
buffer.add(await file.readAsBytes());
|
||||||
|
@ -273,7 +272,7 @@ class ResponseContext extends Extensible {
|
||||||
///
|
///
|
||||||
/// [contentType] can be either a [String], or a [ContentType].
|
/// [contentType] can be either a [String], or a [ContentType].
|
||||||
void serialize(value, {contentType}) {
|
void serialize(value, {contentType}) {
|
||||||
if (!_isOpen) throw _closed();
|
// if (!_isOpen) throw _closed();
|
||||||
var text = serializer(value);
|
var text = serializer(value);
|
||||||
write(text);
|
write(text);
|
||||||
|
|
||||||
|
@ -292,7 +291,7 @@ class ResponseContext extends Extensible {
|
||||||
int sleepMs: 0,
|
int sleepMs: 0,
|
||||||
bool resumable: true,
|
bool resumable: true,
|
||||||
Codec<List<int>, List<int>> codec}) async {
|
Codec<List<int>, List<int>> codec}) async {
|
||||||
if (!_isOpen) throw _closed();
|
// if (!_isOpen) throw _closed();
|
||||||
|
|
||||||
headers[HttpHeaders.CONTENT_TYPE] = lookupMimeType(file.path);
|
headers[HttpHeaders.CONTENT_TYPE] = lookupMimeType(file.path);
|
||||||
end();
|
end();
|
||||||
|
@ -332,7 +331,7 @@ class _LockableBytesBuilderImpl implements _LockableBytesBuilder {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void _lock() {
|
void _lock() {
|
||||||
_closed = true;
|
// _closed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_framework
|
name: angel_framework
|
||||||
version: 1.0.0-dev.72
|
version: 1.0.0-dev.73
|
||||||
description: A high-powered HTTP server with DI, routing and more.
|
description: A high-powered HTTP server with DI, routing and 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