35
This commit is contained in:
parent
5c5ab40876
commit
0057f11661
4 changed files with 29 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
|||
# 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)
|
||||
|
||||
Core libraries for the Angel Framework.
|
|
@ -56,8 +56,7 @@ class RequestContext extends Extensible {
|
|||
Map get query => _body.query;
|
||||
|
||||
/// The remote address requesting this resource.
|
||||
InternetAddress get remoteAddress =>
|
||||
io.connectionInfo.remoteAddress;
|
||||
InternetAddress get remoteAddress => io.connectionInfo.remoteAddress;
|
||||
|
||||
/// The user's HTTP session.
|
||||
HttpSession get session => io.session;
|
||||
|
@ -67,10 +66,7 @@ class RequestContext extends Extensible {
|
|||
|
||||
/// Is this an **XMLHttpRequest**?
|
||||
bool get xhr =>
|
||||
io.headers
|
||||
.value("X-Requested-With")
|
||||
?.trim()
|
||||
?.toLowerCase() ==
|
||||
io.headers.value("X-Requested-With")?.trim()?.toLowerCase() ==
|
||||
'xmlhttprequest';
|
||||
|
||||
@deprecated
|
||||
|
@ -91,7 +87,7 @@ class RequestContext extends Extensible {
|
|||
.replaceAll(new RegExp(r'/+$'), '');
|
||||
ctx._io = request;
|
||||
|
||||
ctx._body = await parseBody(request);
|
||||
ctx._body = (await parseBody(request)) ?? {};
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,9 @@ import '../extensible.dart';
|
|||
import 'angel_base.dart';
|
||||
import 'controller.dart';
|
||||
|
||||
final RegExp _contentType =
|
||||
new RegExp(r'([^/\n]+)\/\s*([^;\n]+)\s*(;\s*charset=([^$;\n]+))?');
|
||||
|
||||
final RegExp _straySlashes = new RegExp(r'(^/+)|(/+$)');
|
||||
|
||||
/// 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`.');
|
||||
}
|
||||
|
||||
/// 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);
|
||||
|
||||
/// Set this to true if you will manually close the response.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel_framework
|
||||
version: 1.0.0-dev.34
|
||||
version: 1.0.0-dev.35
|
||||
description: Core libraries for the Angel framework.
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/angel_framework
|
||||
|
|
Loading…
Reference in a new issue