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

vweb: fix a cookie bug

This commit is contained in:
Alexander Medvednikov 2019-12-13 21:11:40 +03:00
parent 83b8d642b4
commit fb3da327d6

View File

@ -94,7 +94,13 @@ pub fn (ctx mut Context) set_cookie(key, val string) {
} }
pub fn (ctx &Context) get_cookie(key string) ?string { // TODO refactor pub fn (ctx &Context) get_cookie(key string) ?string { // TODO refactor
cookie_header := ' ' + ctx.get_header('cookie') mut cookie_header := ctx.get_header('cookie')
if cookie_header == '' {
cookie_header = ctx.get_header('Cookie')
}
cookie_header = ' ' + cookie_header
//println('cookie_header="$cookie_header"')
//println(ctx.req.headers)
cookie := if cookie_header.contains(';') { cookie := if cookie_header.contains(';') {
cookie_header.find_between(' $key=', ';') cookie_header.find_between(' $key=', ';')
} else { } else {
@ -127,22 +133,22 @@ pub fn run<T>(app mut T, port int) {
//foobar<T>() //foobar<T>()
// TODO move this to handle_conn<T>(conn, app) // TODO move this to handle_conn<T>(conn, app)
message := readall(conn) message := readall(conn)
if message.len > MAX_HTTP_POST_SIZE { if message.len > MAX_HTTP_POST_SIZE {
println('message.len = $message.len > MAX_HTTP_POST_SIZE') println('message.len = $message.len > MAX_HTTP_POST_SIZE')
conn.send_string(HTTP_500) or {} conn.send_string(HTTP_500) or {}
conn.close() or {} conn.close() or {}
continue continue
} }
lines := message.split_into_lines() lines := message.split_into_lines()
if lines.len < 2 { if lines.len < 2 {
conn.send_string(HTTP_500) or {} conn.send_string(HTTP_500) or {}
conn.close() or {} conn.close() or {}
continue continue
} }
first_line := strip(lines[0]) first_line := strip(lines[0])
$if debug { println(first_line) } $if debug { println(first_line) }
// Parse the first line // Parse the first line
@ -167,7 +173,7 @@ pub fn run<T>(app mut T, port int) {
body += strip(sline) + '\r\n' body += strip(sline) + '\r\n'
} }
} }
mut action := vals[1][1..].all_before('/') mut action := vals[1][1..].all_before('/')
if action.contains('?') { if action.contains('?') {
action = action.all_before('?') action = action.all_before('?')