Skip to content

Commit

Permalink
chore(celest): Make request context vendor-neutral
Browse files Browse the repository at this point in the history
  • Loading branch information
dnys1 committed Mar 10, 2024
1 parent f2295b9 commit d003901
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions packages/celest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.1

- Makes request context not specific to Celest

## 0.3.0

- Initial release of Celest Auth with email OTP support
Expand Down
14 changes: 9 additions & 5 deletions packages/celest/lib/src/runtime/serve.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,24 @@ abstract base class CloudFunctionTarget {
init();
}

static const _contextHeaderPrefix = 'X-Celest-Context-';
static const _contextHeaderPrefix = 'X-Context-';
static final _contextHeaderMatcher = RegExp(
_contextHeaderPrefix,
caseSensitive: false,
);

Future<Response> _handler(Request request) async {
final bodyJson = await request.decodeJson();
final context = <String, String>{};
request.headers.forEach((key, value) {
key = key.toLowerCase();
if (key.startsWith(_contextHeaderMatcher)) {
context[key.substring(_contextHeaderPrefix.length)] = value;
}
});
final response = await runZoned(
() => handle({
for (final MapEntry(:key, :value) in request.headers.entries)
if (key.startsWith(_contextHeaderMatcher))
'\$${key.substring(_contextHeaderPrefix.length).toLowerCase()}':
value,
r'$context': context,
...bodyJson,
}),
zoneSpecification: ZoneSpecification(
Expand Down
2 changes: 1 addition & 1 deletion packages/celest/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: celest
description: The Flutter cloud platform. Celest enables you to build your entire backend in Dart.
version: 0.3.0
version: 0.3.1
homepage: https://celest.dev
repository: https://github.com/celest-dev/celest/tree/main/packages/celest

Expand Down

0 comments on commit d003901

Please sign in to comment.