Skip to content

Commit

Permalink
feat: more request utilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
iyifr committed Sep 6, 2024
1 parent 036f5df commit 3756916
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
1 change: 1 addition & 0 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ void main() async {
onRequest: (event) {
// PER REQUEST local state😻
event.context["user"] = 'Ogunlepon';
print(getRequestUrl(event));

setResponseHeader(event,
header: HttpHeaders.contentTypeHeader,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/trie.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Trie {

params.forEach((key, value) {
if (value["leaf"] == true) {
theprms[key] = pathPieces.last;
theprms[key] = pathPieces.lastOrNull ?? "";
} else {
List<String> nw = value["prev"].split("/");
var placeholderChunks = nw..removeWhere((item) => item.isEmpty);
Expand Down
25 changes: 8 additions & 17 deletions lib/utils/req_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,14 @@ String? getRequestHost(H4Event event) {
return event.node["value"]?.headers.value(HttpHeaders.hostHeader);
}

// Future<List<Map<String, dynamic>>?> readMultipartFormData(H4Event event) async {
// var contentType = event.node["value"]?.headers.contentType;
// if (contentType?.mimeType == 'multipart/form-data') {
// var request = event.node["value"];

// final boundary = contentType!.parameters['boundary'];
// if (boundary != null) {
// return await handleMultipartFormdata(request!, boundary);
// } else {
// print('Invalid multipart/form-data request: missing boundary');
// }
// } else {
// print(
// 'Unsupported content type: ${contentType?.mimeType} expected multipart/form-data');
// }
// return null;
// }
String? getRequestUrl(H4Event event) {
return '${getRequestProtocol(event)}://${getRequestHost(event)}${event.path}';
}

/// ### Get the request protocol.
getRequestProtocol(H4Event event) {
return event.node["value"]?.headers.value("x-forwarded-proto") ?? "http";
}

class FormData {
final Map<String, List<String>> _data = {};
Expand Down

0 comments on commit 3756916

Please sign in to comment.