@@ -824,6 +824,8 @@ fn handle_route[A, X](mut app A, mut user_context X, url urllib.URL, host string
824
824
825
825
// Skip if the host does not match or is empty
826
826
if route.host == '' || route.host == host {
827
+ can_have_data_args := user_context.Context.req.method == .post
828
+ || user_context.Context.req.method == .get
827
829
// Route immediate matches first
828
830
// For example URL `/register` matches route `/:user`, but `fn register()`
829
831
// should be called first.
@@ -836,12 +838,19 @@ fn handle_route[A, X](mut app A, mut user_context X, url urllib.URL, host string
836
838
}
837
839
}
838
840
839
- if user_context.Context.req. method == .post && method. args.len > 1 {
840
- // Populate method args with form values
841
+ if method. args.len > 1 && can_have_data_args {
842
+ // Populate method args with form or query values
841
843
mut args := []string {cap: method.args.len + 1 }
844
+ data := if user_context.Context.req.method == .get {
845
+ user_context.Context.query
846
+ } else {
847
+ user_context.Context.form
848
+ }
849
+
842
850
for param in method.args[1 ..] {
843
- args << user_context.Context.form [param.name]
851
+ args << data [param.name]
844
852
}
853
+
845
854
app.$method (mut user_context, args)
846
855
} else {
847
856
app.$method (mut user_context)
@@ -857,7 +866,24 @@ fn handle_route[A, X](mut app A, mut user_context X, url urllib.URL, host string
857
866
}
858
867
}
859
868
860
- app.$method (mut user_context)
869
+ if method.args.len > 1 && can_have_data_args {
870
+ // Populate method args with form or query values
871
+ mut args := []string {cap: method.args.len + 1 }
872
+
873
+ data := if user_context.Context.req.method == .get {
874
+ user_context.Context.query
875
+ } else {
876
+ user_context.Context.form
877
+ }
878
+
879
+ for param in method.args[1 ..] {
880
+ args << data[param.name]
881
+ }
882
+
883
+ app.$method (mut user_context, args)
884
+ } else {
885
+ app.$method (mut user_context)
886
+ }
861
887
return
862
888
}
863
889
0 commit comments