Rename body parsing methods
This commit is contained in:
parent
2cb0797da5
commit
1dec4f3da6
6 changed files with 20 additions and 17 deletions
|
@ -23,4 +23,7 @@ gone.
|
|||
* `HttpRequestContextImpl` and `HttpResponseContextImpl` were renamed to
|
||||
`HttpRequestContext` and `HttpResponseContext`.
|
||||
* Lazy-parsing request bodies is now the default; `Angel.lazyParseBodies` was replaced
|
||||
with `Angel.eagerParseRequestBodies`.
|
||||
with `Angel.eagerParseRequestBodies`.
|
||||
* `Angel.storeOriginalBuffer` -> `Angel.storeRawRequestBuffers`.
|
||||
* The methods `lazyBody`, `lazyFiles`, and `lazyOriginalBuffer` on `ResponseContext` were all
|
||||
replaced with `parseBody`, `parseUploadedFiles`, and `parseRawRequestBuffer`, respectively.
|
|
@ -67,7 +67,7 @@ abstract class RequestContext<RawRequest> {
|
|||
/// If you are lazy-parsing request bodies, but have not manually [parse]d this one,
|
||||
/// then an error will be thrown.
|
||||
///
|
||||
/// **If you are writing a plug-in, use [lazyBody] instead.**
|
||||
/// **If you are writing a plug-in, use [parseBody] instead.**
|
||||
Map get body {
|
||||
if (_body == null)
|
||||
throw _unparsed('body', 'Body');
|
||||
|
@ -83,7 +83,7 @@ abstract class RequestContext<RawRequest> {
|
|||
/// If you are lazy-parsing request bodies, but have not manually [parse]d this one,
|
||||
/// then an error will be thrown.
|
||||
///
|
||||
/// **If you are writing a plug-in, use [lazyFiles] instead.**
|
||||
/// **If you are writing a plug-in, use [parseUploadedFiles] instead.**
|
||||
List<FileUploadInfo> get files {
|
||||
if (_body == null)
|
||||
throw _unparsed('query', 'Files');
|
||||
|
@ -96,7 +96,7 @@ abstract class RequestContext<RawRequest> {
|
|||
/// If you are lazy-parsing request bodies, but have not manually [parse]d this one,
|
||||
/// then an error will be thrown.
|
||||
///
|
||||
/// **If you are writing a plug-in, use [lazyOriginalBuffer] instead.**
|
||||
/// **If you are writing a plug-in, use [parseRawRequestBuffer] instead.**
|
||||
List<int> get originalBuffer {
|
||||
if (_body == null)
|
||||
throw _unparsed('original buffer', 'OriginalBuffer');
|
||||
|
@ -209,15 +209,15 @@ abstract class RequestContext<RawRequest> {
|
|||
bool get acceptsAll => _acceptsAllCache ??= accepts('*/*');
|
||||
|
||||
/// Retrieves the request body if it has already been parsed, or lazy-parses it before returning the body.
|
||||
Future<Map> lazyBody() => parse().then((b) => b.body);
|
||||
Future<Map> parseBody() => parse().then((b) => b.body);
|
||||
|
||||
/// Retrieves the request files if it has already been parsed, or lazy-parses it before returning the files.
|
||||
Future<List<FileUploadInfo>> lazyFiles() => parse().then((b) => b.files);
|
||||
/// Retrieves a list of all uploaded files if it has already been parsed, or lazy-parses it before returning the files.
|
||||
Future<List<FileUploadInfo>> parseUploadedFiles() => parse().then((b) => b.files);
|
||||
|
||||
/// Retrieves the original request buffer if it has already been parsed, or lazy-parses it before returning the files.
|
||||
/// Retrieves the original request buffer if it has already been parsed, or lazy-parses it before returning the buffer..
|
||||
///
|
||||
/// This will return an empty `List` if you have not enabled `storeOriginalBuffer` on your [app] instance.
|
||||
Future<List<int>> lazyOriginalBuffer() =>
|
||||
/// This will return an empty `List` if you have not enabled `keepRawRequestBuffers` on your [Angel] instance.
|
||||
Future<List<int>> parseRawRequestBuffer() =>
|
||||
parse().then((b) => b.originalBuffer);
|
||||
|
||||
/// Retrieves the request body if it has already been parsed, or lazy-parses it before returning the query.
|
||||
|
|
|
@ -132,7 +132,7 @@ class Angel extends Routable {
|
|||
|
||||
/// When set to `true`, the original body bytes will be stored
|
||||
/// on requests. `false` by default.
|
||||
bool storeOriginalBuffer = false;
|
||||
bool keepRawRequestBuffers = false;
|
||||
|
||||
/// A [Container] used to inject dependencies.
|
||||
Container get container => _container;
|
||||
|
|
|
@ -172,7 +172,7 @@ class Service extends Routable {
|
|||
|
||||
Middleware createMiddleware = getAnnotation(service.create, Middleware);
|
||||
post('/', (RequestContext req, ResponseContext res) {
|
||||
return req.lazyBody().then((body) {
|
||||
return req.parseBody().then((body) {
|
||||
return this
|
||||
.create(
|
||||
body,
|
||||
|
@ -210,7 +210,7 @@ class Service extends Routable {
|
|||
Middleware modifyMiddleware = getAnnotation(service.modify, Middleware);
|
||||
patch(
|
||||
'/:id',
|
||||
(RequestContext req, res) => req.lazyBody().then((body) => this.modify(
|
||||
(RequestContext req, res) => req.parseBody().then((body) => this.modify(
|
||||
parseId(req.params['id']),
|
||||
body,
|
||||
mergeMap([
|
||||
|
@ -226,7 +226,7 @@ class Service extends Routable {
|
|||
Middleware updateMiddleware = getAnnotation(service.update, Middleware);
|
||||
post(
|
||||
'/:id',
|
||||
(RequestContext req, res) => req.lazyBody().then((body) => this.update(
|
||||
(RequestContext req, res) => req.parseBody().then((body) => this.update(
|
||||
parseId(req.params['id']),
|
||||
body,
|
||||
mergeMap([
|
||||
|
@ -240,7 +240,7 @@ class Service extends Routable {
|
|||
(updateMiddleware == null) ? [] : updateMiddleware.handlers));
|
||||
put(
|
||||
'/:id',
|
||||
(RequestContext req, res) => req.lazyBody().then((body) => this.update(
|
||||
(RequestContext req, res) => req.parseBody().then((body) => this.update(
|
||||
parseId(req.params['id']),
|
||||
body,
|
||||
mergeMap([
|
||||
|
|
|
@ -144,6 +144,6 @@ class HttpRequestContext extends RequestContext<HttpRequest> {
|
|||
? new MediaType.parse(rawRequest.headers.contentType.toString())
|
||||
: null,
|
||||
rawRequest.uri,
|
||||
storeOriginalBuffer: app.storeOriginalBuffer == true);
|
||||
storeOriginalBuffer: app.keepRawRequestBuffers == true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ main() {
|
|||
middleware: ['interceptor']);
|
||||
app.get('/hello', 'world');
|
||||
app.get('/name/:first/last/:last', (req, res) => req.params);
|
||||
app.post('/lambda', (RequestContext req, res) => req.lazyBody());
|
||||
app.post('/lambda', (RequestContext req, res) => req.parseBody());
|
||||
app.use('/todos/:id', todos);
|
||||
app
|
||||
.get('/greet/:name',
|
||||
|
|
Loading…
Reference in a new issue