From 1d462136bce4d289c424e5473f6ac6b5b509f7f1 Mon Sep 17 00:00:00 2001 From: David Valdespino Pavon <74150333+dvaldespino94@users.noreply.github.com> Date: Tue, 7 Jun 2022 05:52:43 -0400 Subject: [PATCH] net.http: cookie parsing fixes (#14420) --- vlib/net/http/cookie.v | 7 ++++--- vlib/net/http/request.v | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/vlib/net/http/cookie.v b/vlib/net/http/cookie.v index e9536cd920..46647ce932 100644 --- a/vlib/net/http/cookie.v +++ b/vlib/net/http/cookie.v @@ -68,10 +68,11 @@ pub fn read_cookies(h map[string][]string, filter string) []&Cookie { mut line := line_.trim_space() mut part := '' for line.len > 0 { - if line.index_any(';') > 0 { - line_parts := line.split(';') + mut semicolon_position := line.index_any(';') // Store the position of the next semicolon + if semicolon_position > 0 { // So, there is a semicolon, let's parse until that position + line_parts := line[..semicolon_position].split(';') // split the line only until that semicolon + line = line[(semicolon_position + 1)..] // and then skip everything before the semicolon part = line_parts[0] - line = line_parts[1] } else { part = line line = '' diff --git a/vlib/net/http/request.v b/vlib/net/http/request.v index 0a59431b9e..9ad02de6fb 100644 --- a/vlib/net/http/request.v +++ b/vlib/net/http/request.v @@ -214,11 +214,17 @@ pub fn parse_request_head(mut reader io.BufferedReader) ?Request { } header.coerce(canonicalize: true) + mut request_cookies := map[string]string{} + for _, cookie in read_cookies(header.data, '') { + request_cookies[cookie.name] = cookie.value + } + return Request{ method: method url: target.str() header: header version: version + cookies: request_cookies } }