Rename body parsing methods

This commit is contained in:
Tobe O 2018-08-19 23:51:09 -04:00
parent 2cb0797da5
commit 1dec4f3da6
6 changed files with 20 additions and 17 deletions

View file

@ -24,3 +24,6 @@ gone.
`HttpRequestContext` and `HttpResponseContext`. `HttpRequestContext` and `HttpResponseContext`.
* Lazy-parsing request bodies is now the default; `Angel.lazyParseBodies` was replaced * 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.

View file

@ -67,7 +67,7 @@ abstract class RequestContext<RawRequest> {
/// If you are lazy-parsing request bodies, but have not manually [parse]d this one, /// If you are lazy-parsing request bodies, but have not manually [parse]d this one,
/// then an error will be thrown. /// 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 { Map get body {
if (_body == null) if (_body == null)
throw _unparsed('body', 'Body'); 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, /// If you are lazy-parsing request bodies, but have not manually [parse]d this one,
/// then an error will be thrown. /// 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 { List<FileUploadInfo> get files {
if (_body == null) if (_body == null)
throw _unparsed('query', 'Files'); 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, /// If you are lazy-parsing request bodies, but have not manually [parse]d this one,
/// then an error will be thrown. /// 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 { List<int> get originalBuffer {
if (_body == null) if (_body == null)
throw _unparsed('original buffer', 'OriginalBuffer'); throw _unparsed('original buffer', 'OriginalBuffer');
@ -209,15 +209,15 @@ abstract class RequestContext<RawRequest> {
bool get acceptsAll => _acceptsAllCache ??= accepts('*/*'); bool get acceptsAll => _acceptsAllCache ??= accepts('*/*');
/// Retrieves the request body if it has already been parsed, or lazy-parses it before returning the body. /// 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. /// Retrieves a list of all uploaded files if it has already been parsed, or lazy-parses it before returning the files.
Future<List<FileUploadInfo>> lazyFiles() => parse().then((b) => b.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. /// This will return an empty `List` if you have not enabled `keepRawRequestBuffers` on your [Angel] instance.
Future<List<int>> lazyOriginalBuffer() => Future<List<int>> parseRawRequestBuffer() =>
parse().then((b) => b.originalBuffer); parse().then((b) => b.originalBuffer);
/// Retrieves the request body if it has already been parsed, or lazy-parses it before returning the query. /// Retrieves the request body if it has already been parsed, or lazy-parses it before returning the query.

View file

@ -132,7 +132,7 @@ class Angel extends Routable {
/// When set to `true`, the original body bytes will be stored /// When set to `true`, the original body bytes will be stored
/// on requests. `false` by default. /// on requests. `false` by default.
bool storeOriginalBuffer = false; bool keepRawRequestBuffers = false;
/// A [Container] used to inject dependencies. /// A [Container] used to inject dependencies.
Container get container => _container; Container get container => _container;

View file

@ -172,7 +172,7 @@ class Service extends Routable {
Middleware createMiddleware = getAnnotation(service.create, Middleware); Middleware createMiddleware = getAnnotation(service.create, Middleware);
post('/', (RequestContext req, ResponseContext res) { post('/', (RequestContext req, ResponseContext res) {
return req.lazyBody().then((body) { return req.parseBody().then((body) {
return this return this
.create( .create(
body, body,
@ -210,7 +210,7 @@ class Service extends Routable {
Middleware modifyMiddleware = getAnnotation(service.modify, Middleware); Middleware modifyMiddleware = getAnnotation(service.modify, Middleware);
patch( patch(
'/:id', '/:id',
(RequestContext req, res) => req.lazyBody().then((body) => this.modify( (RequestContext req, res) => req.parseBody().then((body) => this.modify(
parseId(req.params['id']), parseId(req.params['id']),
body, body,
mergeMap([ mergeMap([
@ -226,7 +226,7 @@ class Service extends Routable {
Middleware updateMiddleware = getAnnotation(service.update, Middleware); Middleware updateMiddleware = getAnnotation(service.update, Middleware);
post( post(
'/:id', '/:id',
(RequestContext req, res) => req.lazyBody().then((body) => this.update( (RequestContext req, res) => req.parseBody().then((body) => this.update(
parseId(req.params['id']), parseId(req.params['id']),
body, body,
mergeMap([ mergeMap([
@ -240,7 +240,7 @@ class Service extends Routable {
(updateMiddleware == null) ? [] : updateMiddleware.handlers)); (updateMiddleware == null) ? [] : updateMiddleware.handlers));
put( put(
'/:id', '/:id',
(RequestContext req, res) => req.lazyBody().then((body) => this.update( (RequestContext req, res) => req.parseBody().then((body) => this.update(
parseId(req.params['id']), parseId(req.params['id']),
body, body,
mergeMap([ mergeMap([

View file

@ -144,6 +144,6 @@ class HttpRequestContext extends RequestContext<HttpRequest> {
? new MediaType.parse(rawRequest.headers.contentType.toString()) ? new MediaType.parse(rawRequest.headers.contentType.toString())
: null, : null,
rawRequest.uri, rawRequest.uri,
storeOriginalBuffer: app.storeOriginalBuffer == true); storeOriginalBuffer: app.keepRawRequestBuffers == true);
} }
} }

View file

@ -71,7 +71,7 @@ main() {
middleware: ['interceptor']); middleware: ['interceptor']);
app.get('/hello', 'world'); app.get('/hello', 'world');
app.get('/name/:first/last/:last', (req, res) => req.params); 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.use('/todos/:id', todos);
app app
.get('/greet/:name', .get('/greet/:name',