vweb: fixed req type without path (#7792)

pull/7795/head
Louis Schmieder 2021-01-01 21:57:45 +01:00 committed by GitHub
parent 7496c74f7e
commit f7135979f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 32 deletions

View File

@ -389,14 +389,44 @@ 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{}
// Get methods
// Get is default
mut req_method_str := '$req.method'
if req.method == .post {
if 'post' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'post').map(it[1..].split('/'))
}
} else if req.method == .put {
if 'put' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'put').map(it[1..].split('/'))
}
} else if req.method == .patch {
if 'patch' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'patch').map(it[1..].split('/'))
}
} else if req.method == .delete {
if 'delete' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'delete').map(it[1..].split('/'))
}
} else if req.method == .head {
if 'head' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'head').map(it[1..].split('/'))
}
} else if req.method == .options {
if 'options' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'options').map(it[1..].split('/'))
}
} else {
route_words_a = attrs.filter(it.to_lower() != 'get').map(it[1..].split('/'))
}
if attrs.len == 0 { if attrs.len == 0 {
// No routing for this method. If it matches, call it and finish matching // No routing for this method. If it matches, call it and finish matching
// since such methods have a priority. // since such methods have a priority.
// For example URL `/register` matches route `/:user`, but `fn register()` // For example URL `/register` matches route `/:user`, but `fn register()`
// should be called first. // should be called first.
if (req.method == .get && if (req_method_str == '' &&
url_words[0] == method.name && url_words.len == 1) || url_words[0] == method.name && url_words.len == 1) ||
(req.method == .post && url_words[0] + '_post' == method.name) { (req_method_str == req.method.str() && url_words[0] == method.name && url_words.len == 1) {
$if debug { $if debug {
println('easy match method=$method.name') println('easy match method=$method.name')
} }
@ -404,36 +434,6 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T) {
return return
} }
} else { } else {
// Get methods
// Get is default
mut req_method_str := '$req.method'
if req.method == .post {
if 'post' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'post').map(it[1..].split('/'))
}
} else if req.method == .put {
if 'put' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'put').map(it[1..].split('/'))
}
} else if req.method == .patch {
if 'patch' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'patch').map(it[1..].split('/'))
}
} else if req.method == .delete {
if 'delete' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'delete').map(it[1..].split('/'))
}
} else if req.method == .head {
if 'head' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'head').map(it[1..].split('/'))
}
} else if req.method == .options {
if 'options' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'options').map(it[1..].split('/'))
}
} else {
route_words_a = attrs.filter(it.to_lower() != 'get').map(it[1..].split('/'))
}
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 {