diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ec32c1..872cc22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/src/http/session/session_file_store.dart b/lib/src/http/session/session_file_store.dart index 0e2ce1d..d239d2d 100644 --- a/lib/src/http/session/session_file_store.dart +++ b/lib/src/http/session/session_file_store.dart @@ -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 _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 @@ -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 { @@ -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 bytes = await raf.read(length); fileContent = utf8.decode(bytes); @@ -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}), diff --git a/lib/src/route/route_handler.dart b/lib/src/route/route_handler.dart index 50e7c59..bd53fcb 100644 --- a/lib/src/route/route_handler.dart +++ b/lib/src/route/route_handler.dart @@ -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 { diff --git a/lib/src/route/set_static_path.dart b/lib/src/route/set_static_path.dart index ab308b8..c491da8 100644 --- a/lib/src/route/set_static_path.dart +++ b/lib/src/route/set_static_path.dart @@ -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( diff --git a/pubspec.yaml b/pubspec.yaml index ead0def..8d7b1b3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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