Skip to content

Commit d298aa2

Browse files
authored
RequestContext - add request property (#150)
Deprecated headers and headersAll Fixes #127
1 parent 3a63763 commit d298aa2

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

functions_framework/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 0.3.1-dev
4+
5+
- `functions_framework.dart`
6+
7+
- `RequestContext`
8+
- Added `request` property to access original request.
9+
- Deprecated `headers` and `headersAll` - use `request` instead.
10+
311
## 0.3.0
412

513
- Added support for functions that handle and return JSON data.

functions_framework/lib/src/request_context.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,23 @@ import 'logging.dart';
2020

2121
class RequestContext {
2222
final RequestLogger logger;
23-
final Request _request;
2423

25-
final responseHeaders = <String, /* String | List<String> */ Object>{};
24+
/// Access to the source [Request] object.
25+
///
26+
/// Accessing `read` or `readAsString` will throw an error because the body
27+
/// of the [Request] has already been read.
28+
final Request request;
2629

27-
RequestContext._(this._request) : logger = loggerForRequest(_request);
30+
final responseHeaders = <String, /* String | List<String> */ Object>{};
2831

2932
/// The HTTP headers with case-insensitive keys.
3033
///
3134
/// If a header occurs more than once in the query string, they are mapped to
3235
/// by concatenating them with a comma.
3336
///
3437
/// The returned map is unmodifiable.
35-
Map<String, String> get headers => _request.headers;
38+
@Deprecated('Use request.headers instead')
39+
Map<String, String> get headers => request.headers;
3640

3741
/// The HTTP headers with multiple values with case-insensitive keys.
3842
///
@@ -41,7 +45,10 @@ class RequestContext {
4145
/// for that occurrence.
4246
///
4347
/// The returned map and the lists it contains are unmodifiable.
44-
Map<String, List<String>> get headersAll => _request.headersAll;
48+
@Deprecated('Use request.headersAll instead')
49+
Map<String, List<String>> get headersAll => request.headersAll;
50+
51+
RequestContext._(this.request) : logger = loggerForRequest(request);
4552
}
4653

4754
@internal

functions_framework/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: functions_framework
2-
version: 0.3.0
2+
version: 0.3.1-dev
33
description: >-
44
FaaS (Function as a service) framework for writing portable Dart functions
55
repository: https://github.com/GoogleCloudPlatform/functions-framework-dart

0 commit comments

Comments
 (0)