Skip to content

Commit

Permalink
RequestContext - add request property (#150)
Browse files Browse the repository at this point in the history
Deprecated headers and headersAll

Fixes #127
  • Loading branch information
kevmoo authored Dec 27, 2020
1 parent 3a63763 commit d298aa2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
8 changes: 8 additions & 0 deletions functions_framework/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.3.1-dev

- `functions_framework.dart`

- `RequestContext`
- Added `request` property to access original request.
- Deprecated `headers` and `headersAll` - use `request` instead.

## 0.3.0

- Added support for functions that handle and return JSON data.
Expand Down
17 changes: 12 additions & 5 deletions functions_framework/lib/src/request_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@ import 'logging.dart';

class RequestContext {
final RequestLogger logger;
final Request _request;

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

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

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

/// The HTTP headers with multiple values with case-insensitive keys.
///
Expand All @@ -41,7 +45,10 @@ class RequestContext {
/// for that occurrence.
///
/// The returned map and the lists it contains are unmodifiable.
Map<String, List<String>> get headersAll => _request.headersAll;
@Deprecated('Use request.headersAll instead')
Map<String, List<String>> get headersAll => request.headersAll;

RequestContext._(this.request) : logger = loggerForRequest(request);
}

@internal
Expand Down
2 changes: 1 addition & 1 deletion functions_framework/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: functions_framework
version: 0.3.0
version: 0.3.1-dev
description: >-
FaaS (Function as a service) framework for writing portable Dart functions
repository: https://github.com/GoogleCloudPlatform/functions-framework-dart
Expand Down

0 comments on commit d298aa2

Please sign in to comment.