vweb: add url query (#5719)

pull/5724/head
Louis Schmieder 2020-07-07 13:46:57 +02:00 committed by GitHub
parent 4490cd2e8a
commit d2d4ea42ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 3 deletions

View File

@ -49,6 +49,7 @@ pub:
// TODO Response // TODO Response
pub mut: pub mut:
form map[string]string form map[string]string
query map[string]string
headers string // response headers headers string // response headers
done bool done bool
page_gen_start i64 page_gen_start i64
@ -330,18 +331,27 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
// Call the right action // Call the right action
println('route matching...') println('route matching...')
//t := time.ticks() //t := time.ticks()
mut action := '' //mut action := ''
mut route_words := []string{} mut route_words := []string{}
mut ok := true mut ok := true
url_words := vals[1][1..].split('/') mut url_words := vals[1][1..].split('/')
if url_words.len == 0 { if url_words.len == 0 {
app.index() app.index()
conn.close() or {} conn.close() or {}
return return
} else {
if url_words.last().contains('?') {
tmp_query := url_words.last().all_after('?').split('&').map(it.split('='))
url_words[url_words.len - 1] = url_words.last().all_before('?')
for data in tmp_query {
if data.len == 2 {
app.vweb.query[data[0]] = data[1]
}
}
}
} }
mut vars := []string{cap: route_words.len} mut vars := []string{cap: route_words.len}
$for method in T { $for method in T {