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

v0.8.2 #173

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.8.2

- Fix (Session): session file locking issue on Linux.
- Fix (Static File): Automatically load `index.html` if the `/` route is not defined in web routes.

## 0.8.1

- Fix(Request Validation): Custom validation rule Future
Expand Down
37 changes: 0 additions & 37 deletions lib/src/http/session/session_file_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,6 @@ class SessionFileStore {
final String _secretKey = env('APP_KEY');
final String sessionPath = 'storage/framework/sessions';

/// Tries to lock a file in the given mode, with retries in case of failure.
///
/// This method attempts to lock a file in the given mode, and if the
/// operation fails, it waits for the given delay and then retries. This
/// process is repeated for the given number of retries. If the lock
/// operation still fails after the specified number of retries, the
/// exception is rethrown.
///
/// Parameters:
/// - [raf]: The file to lock.
/// - [mode]: The lock mode to use.
/// - [retries]: The number of times to retry the lock operation in
/// case of failure. Defaults to 5.
/// - [delay]: The delay between retries. Defaults to a 150ms delay.
///
Future<void> _lockFile(
RandomAccessFile raf,
FileLock mode, {
int retries = 5,
Duration delay = const Duration(milliseconds: 150),
}) async {
for (int i = 0; i < retries; i++) {
try {
await raf.lock(mode);
return;
} catch (e) {
if (i == retries - 1) {
rethrow;
}
await Future.delayed(delay);
}
}
}

/// Stores session data in a file with the given session ID.
///
/// This method creates or overwrites a file in the session path to store
Expand Down Expand Up @@ -81,7 +47,6 @@ class SessionFileStore {

final raf = await file.open(mode: FileMode.write);
try {
await _lockFile(raf, FileLock.exclusive);
await raf.writeFrom(utf8.encode(content));
} finally {
try {
Expand Down Expand Up @@ -114,7 +79,6 @@ class SessionFileStore {
final raf = await file.open(mode: FileMode.read);
String fileContent = '';
try {
await _lockFile(raf, FileLock.exclusive);
final int length = await raf.length();
final List<int> bytes = await raf.read(length);
fileContent = utf8.decode(bytes);
Expand Down Expand Up @@ -169,7 +133,6 @@ class SessionFileStore {
if (await file.exists()) {
final raf = await file.open(mode: FileMode.write);
try {
await _lockFile(raf, FileLock.exclusive);
int expiration = DateTime.now().toUtc().millisecondsSinceEpoch - 1;
final String content = VaniaEncryption.encryptString(
json.encode({"data": {}, "expiration": expiration}),
Expand Down
2 changes: 2 additions & 0 deletions lib/src/route/route_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ RouteData? httpRouteHandler(HttpRequest req) {
if (route == null) {
if (req.method.toLowerCase() ==
HttpRequestMethod.options.name.toLowerCase()) {
req.response.headers.add('Content-Length', 0);
req.response.statusCode = HttpStatus.ok;
req.response.close();
return null;
} else {
Expand Down
5 changes: 4 additions & 1 deletion lib/src/route/set_static_path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ bool setStaticPath(HttpRequest req) {
),
).path.toLowerCase(),
);
if (!routePath.endsWith("/")) {
if (!routePath.endsWith("/") && req.method.toLowerCase() == 'get') {
if (req.uri.path == '/') {
routePath = 'index.html';
}
File file = File(sanitizeRoutePath("public/$routePath"));
if (file.existsSync()) {
Response response = Response.file(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: vania
description: Fast, simple, and powerful backend framework for Dart built with
version: 0.8.1
version: 0.8.2
homepage: https://vdart.dev
repository: https://github.com/vania-dart/framework
issue_tracker: https://github.com/vania-dart/framework/issues
Expand Down