vweb: fixed req type without path (#7792)
parent
7496c74f7e
commit
f7135979f5
|
@ -389,21 +389,6 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T) {
|
||||||
$if method.return_type is Result {
|
$if method.return_type is Result {
|
||||||
attrs := method.attrs
|
attrs := method.attrs
|
||||||
route_words_a = [][]string{}
|
route_words_a = [][]string{}
|
||||||
if attrs.len == 0 {
|
|
||||||
// No routing for this method. If it matches, call it and finish matching
|
|
||||||
// since such methods have a priority.
|
|
||||||
// For example URL `/register` matches route `/:user`, but `fn register()`
|
|
||||||
// should be called first.
|
|
||||||
if (req.method == .get &&
|
|
||||||
url_words[0] == method.name && url_words.len == 1) ||
|
|
||||||
(req.method == .post && url_words[0] + '_post' == method.name) {
|
|
||||||
$if debug {
|
|
||||||
println('easy match method=$method.name')
|
|
||||||
}
|
|
||||||
app.$method(vars)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Get methods
|
// Get methods
|
||||||
// Get is default
|
// Get is default
|
||||||
mut req_method_str := '$req.method'
|
mut req_method_str := '$req.method'
|
||||||
|
@ -434,6 +419,21 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T) {
|
||||||
} else {
|
} else {
|
||||||
route_words_a = attrs.filter(it.to_lower() != 'get').map(it[1..].split('/'))
|
route_words_a = attrs.filter(it.to_lower() != 'get').map(it[1..].split('/'))
|
||||||
}
|
}
|
||||||
|
if attrs.len == 0 {
|
||||||
|
// No routing for this method. If it matches, call it and finish matching
|
||||||
|
// since such methods have a priority.
|
||||||
|
// For example URL `/register` matches route `/:user`, but `fn register()`
|
||||||
|
// should be called first.
|
||||||
|
if (req_method_str == '' &&
|
||||||
|
url_words[0] == method.name && url_words.len == 1) ||
|
||||||
|
(req_method_str == req.method.str() && url_words[0] == method.name && url_words.len == 1) {
|
||||||
|
$if debug {
|
||||||
|
println('easy match method=$method.name')
|
||||||
|
}
|
||||||
|
app.$method(vars)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
mut req_method := []string{}
|
mut req_method := []string{}
|
||||||
if route_words_a.len > 0 {
|
if route_words_a.len > 0 {
|
||||||
for route_words in route_words_a {
|
for route_words in route_words_a {
|
||||||
|
|
Loading…
Reference in New Issue