Skip to content

Commit

Permalink
feat/extend: readFormData properly handles undefined behaviour.
Browse files Browse the repository at this point in the history
  • Loading branch information
iyifr committed Oct 8, 2024
1 parent 14e3b54 commit e267cdb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void main() async {
app.use(apiRouter, basePath: '/api');

router.get("/vamos/:id/base/:studentId", (event) {
return getRouteParam(event, name: "id");
return getRouteParam(event, name: "studentId");
});

apiRouter.get("/signup", (event) async {
Expand Down
3 changes: 0 additions & 3 deletions bin/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import 'package:h4/utils/req_utils.dart';
void main(List<String> arguments) async {
var app = createApp(
port: 5173,
onRequest: (event) {
handleCors(event, origin: "https://example.re");
},
);

var router = createRouter();
Expand Down
2 changes: 1 addition & 1 deletion lib/src/h4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Either<T, U> {

void Function(String error, String? stackTrace, H4Event? event)
defaultErrorMiddleware = (error, stackTrace, event) => logger.severe(
'$error\n $stackTrace Error occured while attempting ${event?.method.toUpperCase()} request at - ${event?.path}');
'$error\n$stackTrace Error occured while attempting ${event?.method.toUpperCase()} request at - ${event?.path}');

/// A middleware function that takes an [H4Event] and has access to it's snapshot.
typedef Middleware = void Function(H4Event event)?;
Expand Down
6 changes: 6 additions & 0 deletions lib/utils/req_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'dart:io';

import 'package:h4/create.dart';
import 'package:h4/src/logger.dart';
import 'package:mime/mime.dart';

export 'package:h4/utils/req_utils.dart' hide handleMultipartFormdata, FormData;
Expand Down Expand Up @@ -120,6 +121,11 @@ Future<FormData> readFormData(dynamic event) async {
final contentType = request.headers.contentType;
var formData = FormData();

if (contentType?.mimeType == null) {
logger.warning("NO formdata fields in request body!");
throw CreateError(message: "No formdata fields found");
}

if (contentType?.mimeType == 'multipart/form-data') {
final boundary = contentType!.parameters['boundary'];
if (boundary != null) {
Expand Down

0 comments on commit e267cdb

Please sign in to comment.