Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.4.0 #26

Merged
merged 41 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ea31463
chore: update readme
francescovallone Jun 2, 2024
af4a326
chore: change benchmark table build
francescovallone Jun 2, 2024
479e38f
chore: new benchmarks
francescovallone Jun 2, 2024
fef511f
chore: update readme
francescovallone Jun 2, 2024
5eae7ec
Merge branch 'develop' of https://github.com/francescovallone/serinus…
francescovallone Jun 2, 2024
874511d
feat(#14): add a first version of response events
francescovallone Jun 3, 2024
7f1da6a
feat(#14): add a first version of response events
francescovallone Jun 3, 2024
4122eed
Merge branch 'feat/14' of https://github.com/francescovallone/serinus…
francescovallone Jun 3, 2024
8d930a7
feat(#14): change response flow to use the events
francescovallone Jun 3, 2024
0dfc936
feat(#14): add test for response events
francescovallone Jun 5, 2024
cf9627b
feat(#18): initial implementation
francescovallone Jun 5, 2024
99ee290
feat(#14): export the response event enum, and remove unnecessary imp…
francescovallone Jun 5, 2024
ad8c755
Merge pull request #19 from francescovallone/feat/14
francescovallone Jun 5, 2024
4f89524
feat(#17): the file is now read as a stream and it is sent correctly …
francescovallone Jun 5, 2024
b981518
Merge pull request #20 from francescovallone/feat/17
francescovallone Jun 5, 2024
faaadf6
fix(#22): add further checks to 'get' method in controllers to preven…
francescovallone Jun 7, 2024
ddf0bbe
feat(#16): add factory constructors to Route and remove abstract modi…
francescovallone Jun 7, 2024
153d0de
docs(#15): add request_lifecycle and base path to docs
francescovallone Jun 7, 2024
ff5e9b4
fix(#18): remove execution context, simplify context creation
francescovallone Jun 7, 2024
c66cec0
feat(#18): initial implementation
francescovallone Jun 5, 2024
d1d4b92
fix(#18): remove execution context, simplify context creation
francescovallone Jun 7, 2024
8f7aee3
feat(#18)!: remove pipes
francescovallone Jun 7, 2024
8ad9644
test(#18): remove pipes reference from tests
francescovallone Jun 7, 2024
25535cc
feat(#18): finalize hooks, add transform and parse methods to route
francescovallone Jun 7, 2024
c47244d
feat(#18): finalize hooks, add transform and parse methods to route
francescovallone Jun 7, 2024
d5de627
feat(#18): add local version of before and after handle
francescovallone Jun 8, 2024
0f30768
docs(#15): start request lifecycle page
francescovallone Jun 8, 2024
f86225a
feat(#18)!: remove guards and middlewares
francescovallone Jun 8, 2024
409233b
chore: add dockerfile for documentation
francescovallone Jun 8, 2024
ebe56c8
fix: change vuepress to vitepress
francescovallone Jun 8, 2024
82d876d
feat(#18): re-add middlewares
francescovallone Jun 9, 2024
d7610dc
docs(#15): new homepage for serinus docs
francescovallone Jun 9, 2024
98e785d
feat(#18): re-enable middlewares tests and fix issue on request object
francescovallone Jun 9, 2024
694df9f
feat(#15): add correct lifecycle image
francescovallone Jun 9, 2024
3d809e4
Merge pull request #23 from francescovallone/docs/15
francescovallone Jun 9, 2024
42af888
docs(#16): add corresponding documentation
francescovallone Jun 9, 2024
4404949
Merge pull request #24 from francescovallone/feat/16
francescovallone Jun 9, 2024
7b69876
Merge branch 'develop' into feat/18
francescovallone Jun 9, 2024
8ba97a9
Merge pull request #25 from francescovallone/feat/18
francescovallone Jun 9, 2024
027234a
docs: remove guards file and guard reference in routes
francescovallone Jun 9, 2024
a028f69
chore: prepare for release (0.4.0)
francescovallone Jun 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(#17): the file is now read as a stream and it is sent correctly …
…to the user
  • Loading branch information
francescovallone committed Jun 5, 2024
commit 4f8952481107a7f7796668489e941e9a7779f24a
10 changes: 3 additions & 7 deletions packages/serinus/lib/src/http/internal_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,7 @@ class InternalRequest {
/// String body = await request.body();
/// ```
Future<String> body() async {
final data = await bytes();
if (data.isEmpty) {
return '';
}
final en = encoding ?? utf8;
return en.decode(data);
return await (encoding ?? utf8).decoder.bind(original).join();
}

/// This method is used to get the body of the request as a [dynamic] json object
Expand All @@ -145,7 +140,8 @@ class InternalRequest {
/// it is used internally by the [body], the [json] and the [stream] methods
Future<Uint8List> bytes() async {
try {
_bytes ??= await original.firstWhere((element) => element.isNotEmpty);
final data = await body();
_bytes ??= Uint8List.fromList((encoding ?? utf8).encode(data));
return _bytes!;
} catch (_) {
return Uint8List(0);
Expand Down
28 changes: 21 additions & 7 deletions packages/serinus/lib/src/http/internal_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,21 @@ class InternalResponse {
/// After sending the data, the response will be closed.
Future<void> send(List<int> data) async {
_original.add(data);
_events.add(ResponseEvent.data);
_original.close();
_events.add(ResponseEvent.afterSend);
_events.add(ResponseEvent.close);
}

/// This method is used to send a stream of data to the response.
///
/// After sending the stream, the response will be closed.
Future<void> sendStream(Stream<List<int>> stream) async {
await _original.addStream(stream);
_events.add(ResponseEvent.data);
_original.close();
_events.add(ResponseEvent.afterSend);
_events.add(ResponseEvent.close);
}

/// This method is used to set the status code of the response.
Expand Down Expand Up @@ -97,9 +111,6 @@ class InternalResponse {
final rendered = await (result.data is View
? viewEngine!.render(result.data)
: viewEngine!.renderString(result.data));
_events.add(ResponseEvent.data);
_events.add(ResponseEvent.afterSend);
_events.add(ResponseEvent.close);
return send(utf8.encode(rendered));
}
headers(result.headers);
Expand All @@ -111,8 +122,13 @@ class InternalResponse {
if (result.contentLength != null) {
_original.headers.contentLength = result.contentLength!;
}
var data = result.data;
var coding = _original.headers['transfer-encoding']?.join(';');
final data = result.data;
final coding = _original.headers['transfer-encoding']?.join(';');
if(data is File) {
final readPipe = data.openRead();
await sendStream(readPipe);
return;
}
if (coding != null && !equalsIgnoreAsciiCase(coding, 'identity')) {
// If the response is already in a chunked encoding, de-chunk it because
// otherwise `dart:io` will try to add another layer of chunking.
Expand All @@ -131,8 +147,6 @@ class InternalResponse {
_original.headers.set(HttpHeaders.dateHeader, DateTime.now().toUtc());
}
_events.add(ResponseEvent.data);
_events.add(ResponseEvent.afterSend);
_events.add(ResponseEvent.close);
return send(utf8.encode(data.toString()));
}
}
2 changes: 1 addition & 1 deletion packages/serinus/lib/src/http/response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class Response {
factory Response.file(File file,
{int statusCode = 200, ContentType? contentType}) {
return Response._(
file.readAsBytesSync(), statusCode, contentType ?? ContentType.binary);
file, statusCode, contentType ?? ContentType.binary);
}

/// Factory constructor to create a response with a redirect status code.
Expand Down
2 changes: 1 addition & 1 deletion packages/serinus/test/http/responses_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void main() async {

expect(
response.headers.contentType?.mimeType, 'application/octet-stream');
expect(body, '[111, 107, 33]');
expect(body, 'ok!');
});
test(
'''when a 'Response.redirect' is called, then the request should be redirected to the corresponding route''',
Expand Down
Loading