vweb: fix request checking (#6027)

pull/6031/head
Louis Schmieder 2020-07-31 01:26:56 +02:00 committed by GitHub
parent 91c9c0c917
commit 1fd499ed4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 17 deletions

View File

@ -378,28 +378,28 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
} else { } else {
// Get methods // Get methods
// Get is default // Get is default
if 'post' in attrs { if req.method == .post {
if req.method == .post { if 'post' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'post').map(it[1..].split('/')) route_words_a = attrs.filter(it.to_lower() != 'post').map(it[1..].split('/'))
} }
} else if 'put' in attrs { } else if req.method == .put {
if req.method == .put { if 'put' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'put').map(it[1..].split('/')) route_words_a = attrs.filter(it.to_lower() != 'put').map(it[1..].split('/'))
} }
} else if 'patch' in attrs { } else if req.method == .patch {
if req.method == .patch { if 'patch' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'patch').map(it[1..].split('/')) route_words_a = attrs.filter(it.to_lower() != 'patch').map(it[1..].split('/'))
} }
} else if 'delete' in attrs { } else if req.method == .delete {
if req.method == .delete { if 'delete' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'delete').map(it[1..].split('/')) route_words_a = attrs.filter(it.to_lower() != 'delete').map(it[1..].split('/'))
} }
} else if 'head' in attrs { } else if req.method == .head {
if req.method == .head { if 'head' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'head').map(it[1..].split('/')) route_words_a = attrs.filter(it.to_lower() != 'head').map(it[1..].split('/'))
} }
} else if 'options' in attrs { } else if req.method == .options {
if req.method == .options { if 'options' in attrs {
route_words_a = attrs.filter(it.to_lower() != 'options').map(it[1..].split('/')) route_words_a = attrs.filter(it.to_lower() != 'options').map(it[1..].split('/'))
} }
} else { } else {
@ -460,11 +460,6 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
conn.send_string(http_404) or {} conn.send_string(http_404) or {}
return return
} }
send_action<T>(action, vars, mut app)
}
fn send_action<T>(action string, vars []string, mut app T) {
// TODO remove this function
$for method in T.methods { $for method in T.methods {
$if method.@type is Result { $if method.@type is Result {
// search again for method // search again for method