From 1dec4f3da6e112f26ad41d735803f4a40c3d0199 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sun, 19 Aug 2018 23:51:09 -0400 Subject: [PATCH] Rename body parsing methods --- CHANGELOG.md | 5 ++++- lib/src/core/request_context.dart | 18 +++++++++--------- lib/src/core/server.dart | 2 +- lib/src/core/service.dart | 8 ++++---- lib/src/http/http_request_context.dart | 2 +- test/routing_test.dart | 2 +- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17fc0368..db310248 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. \ No newline at end of file +with `Angel.eagerParseRequestBodies`. +* `Angel.storeOriginalBuffer` -> `Angel.storeRawRequestBuffers`. +* The methods `lazyBody`, `lazyFiles`, and `lazyOriginalBuffer` on `ResponseContext` were all +replaced with `parseBody`, `parseUploadedFiles`, and `parseRawRequestBuffer`, respectively. \ No newline at end of file diff --git a/lib/src/core/request_context.dart b/lib/src/core/request_context.dart index 251107d8..dd0930b7 100644 --- a/lib/src/core/request_context.dart +++ b/lib/src/core/request_context.dart @@ -67,7 +67,7 @@ abstract class RequestContext { /// 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 { /// 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 get files { if (_body == null) throw _unparsed('query', 'Files'); @@ -96,7 +96,7 @@ abstract class RequestContext { /// 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 get originalBuffer { if (_body == null) throw _unparsed('original buffer', 'OriginalBuffer'); @@ -209,15 +209,15 @@ abstract class RequestContext { bool get acceptsAll => _acceptsAllCache ??= accepts('*/*'); /// Retrieves the request body if it has already been parsed, or lazy-parses it before returning the body. - Future lazyBody() => parse().then((b) => b.body); + Future 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> 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> 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> lazyOriginalBuffer() => + /// This will return an empty `List` if you have not enabled `keepRawRequestBuffers` on your [Angel] instance. + Future> parseRawRequestBuffer() => parse().then((b) => b.originalBuffer); /// Retrieves the request body if it has already been parsed, or lazy-parses it before returning the query. diff --git a/lib/src/core/server.dart b/lib/src/core/server.dart index bb4db919..f941b51e 100644 --- a/lib/src/core/server.dart +++ b/lib/src/core/server.dart @@ -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; diff --git a/lib/src/core/service.dart b/lib/src/core/service.dart index f914297c..455c891b 100644 --- a/lib/src/core/service.dart +++ b/lib/src/core/service.dart @@ -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([ diff --git a/lib/src/http/http_request_context.dart b/lib/src/http/http_request_context.dart index 9562f764..d0a1b028 100644 --- a/lib/src/http/http_request_context.dart +++ b/lib/src/http/http_request_context.dart @@ -144,6 +144,6 @@ class HttpRequestContext extends RequestContext { ? new MediaType.parse(rawRequest.headers.contentType.toString()) : null, rawRequest.uri, - storeOriginalBuffer: app.storeOriginalBuffer == true); + storeOriginalBuffer: app.keepRawRequestBuffers == true); } } diff --git a/test/routing_test.dart b/test/routing_test.dart index 1eb506f7..e7b4a281 100644 --- a/test/routing_test.dart +++ b/test/routing_test.dart @@ -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',