1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vweb: ensure the tcp connection is always closed at the end of the response

This commit is contained in:
Delyan Angelov 2020-07-10 10:49:39 +03:00
parent beb90435b5
commit ca9790a71f

View File

@ -216,6 +216,7 @@ pub fn run_app<T>(mut app T, port int) {
} }
fn handle_conn<T>(conn net.Socket, mut app T) { fn handle_conn<T>(conn net.Socket, mut app T) {
defer { conn.close() or {} }
//fn handle_conn<T>(conn net.Socket, app_ T) T { //fn handle_conn<T>(conn net.Socket, app_ T) T {
//mut app := app_ //mut app := app_
//first_line := strip(lines[0]) //first_line := strip(lines[0])
@ -232,7 +233,6 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
if vals.len < 2 { if vals.len < 2 {
println('no vals for http') println('no vals for http')
conn.send_string(http_500) or {} conn.send_string(http_500) or {}
conn.close() or {}
return return
//continue //continue
} }
@ -306,7 +306,6 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
$if debug { $if debug {
println('no vals for http') println('no vals for http')
} }
conn.close() or {}
return return
//continue //continue
} }
@ -341,7 +340,6 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
if url_words.len == 0 { if url_words.len == 0 {
app.index() app.index()
conn.close() or {}
return return
} else { } else {
// Parse URL query // Parse URL query
@ -367,7 +365,6 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
if (req.method == 'GET' && url_words[0] == method && url_words.len == 1) || (req.method == 'POST' && url_words[0] + '_post' == method) { if (req.method == 'GET' && url_words[0] == method && url_words.len == 1) || (req.method == 'POST' && url_words[0] + '_post' == method) {
println('easy match method=$method') println('easy match method=$method')
app.$method(vars) app.$method(vars)
conn.close() or {}
return return
} }
} else { } else {
@ -408,7 +405,6 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
if matching && !unknown { if matching && !unknown {
// absolute router words like `/test/site` // absolute router words like `/test/site`
app.$method(vars) app.$method(vars)
conn.close() or {}
return return
} else if matching && unknown { } else if matching && unknown {
// router words with paramter like `/:test/site` // router words with paramter like `/:test/site`
@ -421,11 +417,9 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
if action == '' { if action == '' {
// site not found // site not found
conn.send_string(http_404) or {} conn.send_string(http_404) or {}
conn.close() or {}
return return
} }
send_action<T>(action, vars, mut app) send_action<T>(action, vars, mut app)
return
} }
fn send_action<T>(action string, vars []string, mut app T) { fn send_action<T>(action string, vars []string, mut app T) {