Skip to content

Commit

Permalink
net.http: remove write_set_cookie function
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Dec 15, 2023
1 parent c5887a9 commit 70d10d2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 196 deletions.
16 changes: 0 additions & 16 deletions vlib/net/http/cookie.v
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,6 @@ pub enum SameSite {
same_site_none_mode
}

// Parses all "Set-Cookie" values from the header `h` and
// returns the successfully parsed Cookies.
pub fn read_set_cookies(h map[string][]string) []&Cookie {
cookies_s := h['Set-Cookie']
cookie_count := cookies_s.len
if cookie_count == 0 {
return []
}
mut cookies := []&Cookie{}
for _, line in cookies_s {
c := parse_cookie(line) or { continue }
cookies << &c
}
return cookies
}

// Parses all "Cookie" values from the header `h` and
// returns the successfully parsed Cookies.
//
Expand Down
180 changes: 0 additions & 180 deletions vlib/net/http/cookie_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -252,189 +252,9 @@ const add_cookies_tests = [
raw: 'cookie-1=v1; cookie-2=v2; cookie-3=v3'
},
]
const read_set_cookies_tests = [
ReadSetCookiesTestCase{
header: {
'Set-Cookie': ['Cookie-1=v1']
}
cookies: [&http.Cookie{
name: 'Cookie-1'
value: 'v1'
raw: 'Cookie-1=v1'
}]
},
// ReadSetCookiesTestCase{
// header: {"Set-Cookie": ["NID=99=YsDT5i3E-CXax-; expires=Wed, 23-Nov-2011 01:05:03 GMT; path=/; domain=.google.ch; HttpOnly"]},
// cookies: [&http.Cookie{
// name: "NID",
// value: "99=YsDT5i3E-CXax-",
// path: "/",
// domain: ".google.ch",
// http_only: true,
// expires: time.parse_iso('Wed, 23-Nov-2011 01:05:03 GMT'),
// raw_expires: "Wed, 23-Nov-2011 01:05:03 GMT",
// raw: "NID=99=YsDT5i3E-CXax-; expires=Wed, 23-Nov-2011 01:05:03 GMT; path=/; domain=.google.ch; HttpOnly"
// }]
// },
// ReadSetCookiesTestCase{
// header: {"Set-Cookie": [".ASPXAUTH=7E3AA; expires=Wed, 07-Mar-2012 14:25:06 GMT; path=/; HttpOnly"]},
// cookies: [&http.Cookie{
// name: ".ASPXAUTH",
// value: "7E3AA",
// path: "/",
// expires: time.parse_iso('Wed, 07-Mar-2012 14:25:06 GMT'),
// raw_expires: "Wed, 07-Mar-2012 14:25:06 GMT",
// http_only: true,
// raw: ".ASPXAUTH=7E3AA; expires=Wed, 07-Mar-2012 14:25:06 GMT; path=/; HttpOnly"
// }]
// },
ReadSetCookiesTestCase{
header: {
'Set-Cookie': ['ASP.NET_SessionId=foo; path=/; HttpOnly']
}
cookies: [&http.Cookie{
name: 'ASP.NET_SessionId'
value: 'foo'
path: '/'
http_only: true
raw: 'ASP.NET_SessionId=foo; path=/; HttpOnly'
}]
},
ReadSetCookiesTestCase{
header: {
'Set-Cookie': ['samesitedefault=foo; SameSite']
}
cookies: [&http.Cookie{
name: 'samesitedefault'
value: 'foo'
same_site: .same_site_default_mode
raw: 'samesitedefault=foo; SameSite'
}]
},
ReadSetCookiesTestCase{
header: {
'Set-Cookie': ['samesitelax=foo; SameSite=Lax']
}
cookies: [&http.Cookie{
name: 'samesitelax'
value: 'foo'
same_site: .same_site_lax_mode
raw: 'samesitelax=foo; SameSite=Lax'
}]
},
ReadSetCookiesTestCase{
header: {
'Set-Cookie': ['samesitestrict=foo; SameSite=Strict']
}
cookies: [&http.Cookie{
name: 'samesitestrict'
value: 'foo'
same_site: .same_site_strict_mode
raw: 'samesitestrict=foo; SameSite=Strict'
}]
},
ReadSetCookiesTestCase{
header: {
'Set-Cookie': ['samesitenone=foo; SameSite=None']
}
cookies: [&http.Cookie{
name: 'samesitenone'
value: 'foo'
same_site: .same_site_none_mode
raw: 'samesitenone=foo; SameSite=None'
}]
},
// Make sure we can properly read back the Set-Cookie headers we create
// for values containing spaces or commas:
ReadSetCookiesTestCase{
header: {
'Set-Cookie': ['special-1=a z']
}
cookies: [&http.Cookie{
name: 'special-1'
value: 'a z'
raw: 'special-1=a z'
}]
},
ReadSetCookiesTestCase{
header: {
'Set-Cookie': ['special-2=" z"']
}
cookies: [&http.Cookie{
name: 'special-2'
value: ' z'
raw: 'special-2=" z"'
}]
},
ReadSetCookiesTestCase{
header: {
'Set-Cookie': ['special-3="a "']
}
cookies: [&http.Cookie{
name: 'special-3'
value: 'a '
raw: 'special-3="a "'
}]
},
ReadSetCookiesTestCase{
header: {
'Set-Cookie': ['special-4=" "']
}
cookies: [&http.Cookie{
name: 'special-4'
value: ' '
raw: 'special-4=" "'
}]
},
ReadSetCookiesTestCase{
header: {
'Set-Cookie': ['special-5=a,z']
}
cookies: [&http.Cookie{
name: 'special-5'
value: 'a,z'
raw: 'special-5=a,z'
}]
},
ReadSetCookiesTestCase{
header: {
'Set-Cookie': ['special-6=",z"']
}
cookies: [&http.Cookie{
name: 'special-6'
value: ',z'
raw: 'special-6=",z"'
}]
},
ReadSetCookiesTestCase{
header: {
'Set-Cookie': ['special-7=","']
}
cookies: [&http.Cookie{
name: 'special-7'
value: ','
raw: 'special-8=","'
}]
},
// TODO(bradfitz): users have reported seeing this in the
// wild, but do browsers handle it? RFC 6265 just says "don't
// do that" (section 3) and then never mentions header folding
// again.
// Header{"Set-Cookie": ["ASP.NET_SessionId=foo; path=/; HttpOnly, .ASPXAUTH=7E3AA; expires=Wed, 07-Mar-2012 14:25:06 GMT; path=/; HttpOnly"]},
]

fn test_write_set_cookies() {
for _, tt in write_set_cookie_tests {
assert tt.cookie.str() == tt.raw
}
}

fn test_read_set_cookies() {
for _, tt in read_set_cookies_tests {
h := tt.header['Set-Cookie'][0]
c := http.read_set_cookies(tt.header)
println(h)
println(c[0].str())
assert c[0].str() == h
}
}

0 comments on commit 70d10d2

Please sign in to comment.