From a3b14e00a2d2dfc6206cf35b8cdda6895ffd1eca Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 26 Nov 2019 13:54:41 +0300 Subject: [PATCH] vweb fixes --- vlib/compiler/fn.v | 4 +++- vlib/compiler/main.v | 4 +++- vlib/net/socket.v | 2 ++ vlib/vweb/vweb.v | 50 ++++++++++++++++++++++++++------------------ 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/vlib/compiler/fn.v b/vlib/compiler/fn.v index 46a69ebcce..46002bbfa6 100644 --- a/vlib/compiler/fn.v +++ b/vlib/compiler/fn.v @@ -587,7 +587,9 @@ fn (p mut Parser) check_unused_variables() { if var.name == '' { break } - if !var.is_used && !p.pref.is_repl && !var.is_arg && !p.pref.translated { + if !var.is_used && !p.pref.is_repl && !var.is_arg && + !p.pref.translated && var.name != 'tmpl_res' + { p.production_error_with_token_index('`$var.name` declared and not used', var.token_idx ) } if !var.is_changed && var.is_mut && !p.pref.is_repl && diff --git a/vlib/compiler/main.v b/vlib/compiler/main.v index 8f4fafc314..be1ab2da73 100644 --- a/vlib/compiler/main.v +++ b/vlib/compiler/main.v @@ -502,7 +502,9 @@ pub fn (v mut V) generate_main() { else if v.table.main_exists() { v.gen_main_start(true) cgen.genln(' main__main();') - cgen.genln('free(g_str_buf);') + if !v.pref.is_bare { + cgen.genln('free(g_str_buf);') + } v.gen_main_end('return 0') } } diff --git a/vlib/net/socket.v b/vlib/net/socket.v index 8258cb3435..2bcd78b333 100644 --- a/vlib/net/socket.v +++ b/vlib/net/socket.v @@ -318,3 +318,5 @@ pub fn (s Socket) get_port() int { C.getsockname(s.sockfd, &addr, &size) return C.ntohs(addr.sin_port) } + + diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 7914e5e4b7..f26c9084af 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -143,7 +143,17 @@ pub fn run(app mut T, port int) { } //} if req.method in methods_with_form { - app.vweb.parse_form(s) + for { + line := conn.read_line() + if line == '' || line == '\r\n' { + break + } + //if line.contains('POST') || line == '' { + //break + //} + } + line := conn.read_line() + app.vweb.parse_form(line) } if vals.len < 2 { $if debug { @@ -175,27 +185,27 @@ fn (ctx mut Context) parse_form(s string) { if !(ctx.req.method in methods_with_form) { return } - pos := s.index('\r\n\r\n') - if pos > -1 { - mut str_form := s[pos..s.len] - str_form = str_form.replace('+', ' ') - words := str_form.split('&') - for word in words { - $if debug { - println('parse form keyval="$word"') - } - keyval := word.trim_space().split('=') - if keyval.len != 2 { continue } - key := keyval[0] - val := urllib.query_unescape(keyval[1]) or { - continue - } - $if debug { - println('http form "$key" => "$val"') - } - ctx.form[key] = val + //pos := s.index('\r\n\r\n') + //if pos > -1 { + mut str_form := s//[pos..s.len] + str_form = str_form.replace('+', ' ') + words := str_form.split('&') + for word in words { + $if debug { + println('parse form keyval="$word"') } + keyval := word.trim_space().split('=') + if keyval.len != 2 { continue } + key := keyval[0] + val := urllib.query_unescape(keyval[1]) or { + continue + } + $if debug { + println('http form "$key" => "$val"') + } + ctx.form[key] = val } + //} } fn (ctx mut Context) scan_static_directory(directory_path, mount_path string) {