This commit is contained in:
thosakwe 2016-12-20 22:10:03 -05:00
parent 5c5ab40876
commit 0057f11661
4 changed files with 29 additions and 9 deletions

View file

@ -1,6 +1,6 @@
# angel_framework # angel_framework
[![pub 1.0.0-dev.34](https://img.shields.io/badge/pub-1.0.0--dev.34-red.svg)](https://pub.dartlang.org/packages/angel_framework) [![pub 1.0.0-dev.35](https://img.shields.io/badge/pub-1.0.0--dev.35-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)
Core libraries for the Angel Framework. Core libraries for the Angel Framework.

View file

@ -56,8 +56,7 @@ class RequestContext extends Extensible {
Map get query => _body.query; Map get query => _body.query;
/// The remote address requesting this resource. /// The remote address requesting this resource.
InternetAddress get remoteAddress => InternetAddress get remoteAddress => io.connectionInfo.remoteAddress;
io.connectionInfo.remoteAddress;
/// The user's HTTP session. /// The user's HTTP session.
HttpSession get session => io.session; HttpSession get session => io.session;
@ -67,10 +66,7 @@ class RequestContext extends Extensible {
/// Is this an **XMLHttpRequest**? /// Is this an **XMLHttpRequest**?
bool get xhr => bool get xhr =>
io.headers io.headers.value("X-Requested-With")?.trim()?.toLowerCase() ==
.value("X-Requested-With")
?.trim()
?.toLowerCase() ==
'xmlhttprequest'; 'xmlhttprequest';
@deprecated @deprecated
@ -91,7 +87,7 @@ class RequestContext extends Extensible {
.replaceAll(new RegExp(r'/+$'), ''); .replaceAll(new RegExp(r'/+$'), '');
ctx._io = request; ctx._io = request;
ctx._body = await parseBody(request); ctx._body = (await parseBody(request)) ?? {};
return ctx; return ctx;
} }

View file

@ -10,6 +10,9 @@ import '../extensible.dart';
import 'angel_base.dart'; import 'angel_base.dart';
import 'controller.dart'; import 'controller.dart';
final RegExp _contentType =
new RegExp(r'([^/\n]+)\/\s*([^;\n]+)\s*(;\s*charset=([^$;\n]+))?');
final RegExp _straySlashes = new RegExp(r'(^/+)|(/+$)'); final RegExp _straySlashes = new RegExp(r'(^/+)|(/+$)');
/// A convenience wrapper around an outgoing HTTP request. /// A convenience wrapper around an outgoing HTTP request.
@ -52,6 +55,27 @@ class ResponseContext extends Extensible {
'`ResponseContext#underlyingResponse` is deprecated. Please update your application to use the newer `ResponseContext#io`.'); '`ResponseContext#underlyingResponse` is deprecated. Please update your application to use the newer `ResponseContext#io`.');
} }
/// Gets the Content-Type header.
ContentType get contentType {
if (!headers.containsKey(HttpHeaders.CONTENT_TYPE)) return null;
var header = headers[HttpHeaders.CONTENT_TYPE];
var match = _contentType.firstMatch(header);
if (match == null)
throw new Exception('Malformed Content-Type response header: "$header".');
if (match[4]?.isNotEmpty != true)
return new ContentType(match[1], match[2]);
else
return new ContentType(match[1], match[2], charset: match[4]);
}
/// Sets the Content-Type header.
void set contentType(ContentType contentType) {
headers[HttpHeaders.CONTENT_TYPE] = contentType.toString();
}
ResponseContext(this.io, this.app); ResponseContext(this.io, this.app);
/// Set this to true if you will manually close the response. /// Set this to true if you will manually close the response.

View file

@ -1,5 +1,5 @@
name: angel_framework name: angel_framework
version: 1.0.0-dev.34 version: 1.0.0-dev.35
description: Core libraries for the Angel framework. description: Core libraries for the Angel framework.
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