@@ -252,189 +252,9 @@ const add_cookies_tests = [
252252 raw: 'cookie-1=v1; cookie-2=v2; cookie-3=v3'
253253 },
254254]
255- const read_set_cookies_tests = [
256- ReadSetCookiesTestCase{
257- header: {
258- 'Set-Cookie' : ['Cookie-1=v1' ]
259- }
260- cookies: [& http.Cookie{
261- name: 'Cookie-1'
262- value: 'v1'
263- raw: 'Cookie-1=v1'
264- }]
265- },
266- // ReadSetCookiesTestCase{
267- // header: {"Set-Cookie": ["NID=99=YsDT5i3E-CXax-; expires=Wed, 23-Nov-2011 01:05:03 GMT; path=/; domain=.google.ch; HttpOnly"]},
268- // cookies: [&http.Cookie{
269- // name: "NID",
270- // value: "99=YsDT5i3E-CXax-",
271- // path: "/",
272- // domain: ".google.ch",
273- // http_only: true,
274- // expires: time.parse_iso('Wed, 23-Nov-2011 01:05:03 GMT'),
275- // raw_expires: "Wed, 23-Nov-2011 01:05:03 GMT",
276- // raw: "NID=99=YsDT5i3E-CXax-; expires=Wed, 23-Nov-2011 01:05:03 GMT; path=/; domain=.google.ch; HttpOnly"
277- // }]
278- // },
279- // ReadSetCookiesTestCase{
280- // header: {"Set-Cookie": [".ASPXAUTH=7E3AA; expires=Wed, 07-Mar-2012 14:25:06 GMT; path=/; HttpOnly"]},
281- // cookies: [&http.Cookie{
282- // name: ".ASPXAUTH",
283- // value: "7E3AA",
284- // path: "/",
285- // expires: time.parse_iso('Wed, 07-Mar-2012 14:25:06 GMT'),
286- // raw_expires: "Wed, 07-Mar-2012 14:25:06 GMT",
287- // http_only: true,
288- // raw: ".ASPXAUTH=7E3AA; expires=Wed, 07-Mar-2012 14:25:06 GMT; path=/; HttpOnly"
289- // }]
290- // },
291- ReadSetCookiesTestCase{
292- header: {
293- 'Set-Cookie' : ['ASP.NET_SessionId=foo; path=/; HttpOnly' ]
294- }
295- cookies: [& http.Cookie{
296- name: 'ASP.NET_SessionId'
297- value: 'foo'
298- path: '/'
299- http_only: true
300- raw: 'ASP.NET_SessionId=foo; path=/; HttpOnly'
301- }]
302- },
303- ReadSetCookiesTestCase{
304- header: {
305- 'Set-Cookie' : ['samesitedefault=foo; SameSite' ]
306- }
307- cookies: [& http.Cookie{
308- name: 'samesitedefault'
309- value: 'foo'
310- same_site: .same_site_default_mode
311- raw: 'samesitedefault=foo; SameSite'
312- }]
313- },
314- ReadSetCookiesTestCase{
315- header: {
316- 'Set-Cookie' : ['samesitelax=foo; SameSite=Lax' ]
317- }
318- cookies: [& http.Cookie{
319- name: 'samesitelax'
320- value: 'foo'
321- same_site: .same_site_lax_mode
322- raw: 'samesitelax=foo; SameSite=Lax'
323- }]
324- },
325- ReadSetCookiesTestCase{
326- header: {
327- 'Set-Cookie' : ['samesitestrict=foo; SameSite=Strict' ]
328- }
329- cookies: [& http.Cookie{
330- name: 'samesitestrict'
331- value: 'foo'
332- same_site: .same_site_strict_mode
333- raw: 'samesitestrict=foo; SameSite=Strict'
334- }]
335- },
336- ReadSetCookiesTestCase{
337- header: {
338- 'Set-Cookie' : ['samesitenone=foo; SameSite=None' ]
339- }
340- cookies: [& http.Cookie{
341- name: 'samesitenone'
342- value: 'foo'
343- same_site: .same_site_none_mode
344- raw: 'samesitenone=foo; SameSite=None'
345- }]
346- },
347- // Make sure we can properly read back the Set-Cookie headers we create
348- // for values containing spaces or commas:
349- ReadSetCookiesTestCase{
350- header: {
351- 'Set-Cookie' : ['special-1=a z' ]
352- }
353- cookies: [& http.Cookie{
354- name: 'special-1'
355- value: 'a z'
356- raw: 'special-1=a z'
357- }]
358- },
359- ReadSetCookiesTestCase{
360- header: {
361- 'Set-Cookie' : ['special-2=" z"' ]
362- }
363- cookies: [& http.Cookie{
364- name: 'special-2'
365- value: ' z'
366- raw: 'special-2=" z"'
367- }]
368- },
369- ReadSetCookiesTestCase{
370- header: {
371- 'Set-Cookie' : ['special-3="a "' ]
372- }
373- cookies: [& http.Cookie{
374- name: 'special-3'
375- value: 'a '
376- raw: 'special-3="a "'
377- }]
378- },
379- ReadSetCookiesTestCase{
380- header: {
381- 'Set-Cookie' : ['special-4=" "' ]
382- }
383- cookies: [& http.Cookie{
384- name: 'special-4'
385- value: ' '
386- raw: 'special-4=" "'
387- }]
388- },
389- ReadSetCookiesTestCase{
390- header: {
391- 'Set-Cookie' : ['special-5=a,z' ]
392- }
393- cookies: [& http.Cookie{
394- name: 'special-5'
395- value: 'a,z'
396- raw: 'special-5=a,z'
397- }]
398- },
399- ReadSetCookiesTestCase{
400- header: {
401- 'Set-Cookie' : ['special-6=",z"' ]
402- }
403- cookies: [& http.Cookie{
404- name: 'special-6'
405- value: ',z'
406- raw: 'special-6=",z"'
407- }]
408- },
409- ReadSetCookiesTestCase{
410- header: {
411- 'Set-Cookie' : ['special-7=","' ]
412- }
413- cookies: [& http.Cookie{
414- name: 'special-7'
415- value: ','
416- raw: 'special-8=","'
417- }]
418- },
419- // TODO(bradfitz): users have reported seeing this in the
420- // wild, but do browsers handle it? RFC 6265 just says "don't
421- // do that" (section 3) and then never mentions header folding
422- // again.
423- // Header{"Set-Cookie": ["ASP.NET_SessionId=foo; path=/; HttpOnly, .ASPXAUTH=7E3AA; expires=Wed, 07-Mar-2012 14:25:06 GMT; path=/; HttpOnly"]},
424- ]
425255
426256fn test_write_set_cookies () {
427257 for _, tt in write_set_cookie_tests {
428258 assert tt.cookie.str () == tt.raw
429259 }
430260}
431-
432- fn test_read_set_cookies () {
433- for _, tt in read_set_cookies_tests {
434- h := tt.header['Set-Cookie' ][0 ]
435- c := http.read_set_cookies (tt.header)
436- println (h)
437- println (c[0 ].str ())
438- assert c[0 ].str () == h
439- }
440- }
0 commit comments