From d2d4ea42cec143221a83503490c60861240b9fba Mon Sep 17 00:00:00 2001 From: Louis Schmieder Date: Tue, 7 Jul 2020 13:46:57 +0200 Subject: [PATCH] vweb: add url query (#5719) --- vlib/vweb/vweb.v | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 812a183108..ab6ded1de9 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -49,6 +49,7 @@ pub: // TODO Response pub mut: form map[string]string + query map[string]string headers string // response headers done bool page_gen_start i64 @@ -330,18 +331,27 @@ fn handle_conn(conn net.Socket, mut app T) { // Call the right action println('route matching...') //t := time.ticks() - mut action := '' + //mut action := '' mut route_words := []string{} mut ok := true - url_words := vals[1][1..].split('/') + mut url_words := vals[1][1..].split('/') if url_words.len == 0 { app.index() conn.close() or {} 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} $for method in T {