@@ -74,9 +74,9 @@ type Cookie struct {
74
74
domain []byte
75
75
path []byte
76
76
77
- buf []byte
77
+ bufK []byte
78
+ bufV []byte
78
79
79
- bufKV argsKV
80
80
maxAge int
81
81
82
82
sameSite CookieSameSite
@@ -156,14 +156,14 @@ func (c *Cookie) Path() []byte {
156
156
157
157
// SetPath sets cookie path.
158
158
func (c * Cookie ) SetPath (path string ) {
159
- c .buf = append (c .buf [:0 ], path ... )
160
- c .path = normalizePath (c .path , c .buf )
159
+ c .bufK = append (c .bufK [:0 ], path ... )
160
+ c .path = normalizePath (c .path , c .bufK )
161
161
}
162
162
163
163
// SetPathBytes sets cookie path.
164
164
func (c * Cookie ) SetPathBytes (path []byte ) {
165
- c .buf = append (c .buf [:0 ], path ... )
166
- c .path = normalizePath (c .path , c .buf )
165
+ c .bufK = append (c .bufK [:0 ], path ... )
166
+ c .path = normalizePath (c .path , c .bufK )
167
167
}
168
168
169
169
// Domain returns cookie domain.
@@ -284,11 +284,11 @@ func (c *Cookie) AppendBytes(dst []byte) []byte {
284
284
dst = append (dst , '=' )
285
285
dst = AppendUint (dst , c .maxAge )
286
286
} else if ! c .expire .IsZero () {
287
- c .bufKV . value = AppendHTTPDate (c .bufKV . value [:0 ], c .expire )
287
+ c .bufV = AppendHTTPDate (c .bufV [:0 ], c .expire )
288
288
dst = append (dst , ';' , ' ' )
289
289
dst = append (dst , strCookieExpires ... )
290
290
dst = append (dst , '=' )
291
- dst = append (dst , c .bufKV . value ... )
291
+ dst = append (dst , c .bufV ... )
292
292
}
293
293
if len (c .domain ) > 0 {
294
294
dst = appendCookiePart (dst , strCookieDomain , c .domain )
@@ -336,8 +336,8 @@ func (c *Cookie) AppendBytes(dst []byte) []byte {
336
336
// The returned value is valid until the Cookie reused or released (ReleaseCookie).
337
337
// Do not store references to the returned value. Make copies instead.
338
338
func (c * Cookie ) Cookie () []byte {
339
- c .buf = c .AppendBytes (c .buf [:0 ])
340
- return c .buf
339
+ c .bufK = c .AppendBytes (c .bufK [:0 ])
340
+ return c .bufK
341
341
}
342
342
343
343
// String returns cookie representation.
@@ -357,8 +357,8 @@ var errNoCookies = errors.New("no cookies found")
357
357
358
358
// Parse parses Set-Cookie header.
359
359
func (c * Cookie ) Parse (src string ) error {
360
- c .buf = append (c .buf [:0 ], src ... )
361
- return c .ParseBytes (c .buf )
360
+ c .bufK = append (c .bufK [:0 ], src ... )
361
+ return c .ParseBytes (c .bufK )
362
362
}
363
363
364
364
// ParseBytes parses Set-Cookie header.
@@ -368,30 +368,29 @@ func (c *Cookie) ParseBytes(src []byte) error {
368
368
var s cookieScanner
369
369
s .b = src
370
370
371
- kv := & c .bufKV
372
- if ! s .next (kv ) {
371
+ if ! s .next (& c .bufK , & c .bufV ) {
373
372
return errNoCookies
374
373
}
375
374
376
- c .key = append (c .key , kv . key ... )
377
- c .value = append (c .value , kv . value ... )
375
+ c .key = append (c .key , c . bufK ... )
376
+ c .value = append (c .value , c . bufV ... )
378
377
379
- for s .next (kv ) {
380
- if len (kv . key ) != 0 {
378
+ for s .next (& c . bufK , & c . bufV ) {
379
+ if len (c . bufK ) != 0 {
381
380
// Case insensitive switch on first char
382
- switch kv . key [0 ] | 0x20 {
381
+ switch c . bufK [0 ] | 0x20 {
383
382
case 'm' :
384
- if caseInsensitiveCompare (strCookieMaxAge , kv . key ) {
385
- maxAge , err := ParseUint (kv . value )
383
+ if caseInsensitiveCompare (strCookieMaxAge , c . bufK ) {
384
+ maxAge , err := ParseUint (c . bufV )
386
385
if err != nil {
387
386
return err
388
387
}
389
388
c .maxAge = maxAge
390
389
}
391
390
392
391
case 'e' : // "expires"
393
- if caseInsensitiveCompare (strCookieExpires , kv . key ) {
394
- v := b2s (kv . value )
392
+ if caseInsensitiveCompare (strCookieExpires , c . bufK ) {
393
+ v := b2s (c . bufV )
395
394
// Try the same two formats as net/http
396
395
// See: https://github.com/golang/go/blob/00379be17e63a5b75b3237819392d2dc3b313a27/src/net/http/cookie.go#L133-L135
397
396
exptime , err := time .ParseInLocation (time .RFC1123 , v , time .UTC )
@@ -405,52 +404,52 @@ func (c *Cookie) ParseBytes(src []byte) error {
405
404
}
406
405
407
406
case 'd' : // "domain"
408
- if caseInsensitiveCompare (strCookieDomain , kv . key ) {
409
- c .domain = append (c .domain , kv . value ... )
407
+ if caseInsensitiveCompare (strCookieDomain , c . bufK ) {
408
+ c .domain = append (c .domain , c . bufV ... )
410
409
}
411
410
412
411
case 'p' : // "path"
413
- if caseInsensitiveCompare (strCookiePath , kv . key ) {
414
- c .path = append (c .path , kv . value ... )
412
+ if caseInsensitiveCompare (strCookiePath , c . bufK ) {
413
+ c .path = append (c .path , c . bufV ... )
415
414
}
416
415
417
416
case 's' : // "samesite"
418
- if caseInsensitiveCompare (strCookieSameSite , kv . key ) {
419
- if len (kv . value ) > 0 {
417
+ if caseInsensitiveCompare (strCookieSameSite , c . bufK ) {
418
+ if len (c . bufV ) > 0 {
420
419
// Case insensitive switch on first char
421
- switch kv . value [0 ] | 0x20 {
420
+ switch c . bufV [0 ] | 0x20 {
422
421
case 'l' : // "lax"
423
- if caseInsensitiveCompare (strCookieSameSiteLax , kv . value ) {
422
+ if caseInsensitiveCompare (strCookieSameSiteLax , c . bufV ) {
424
423
c .sameSite = CookieSameSiteLaxMode
425
424
}
426
425
case 's' : // "strict"
427
- if caseInsensitiveCompare (strCookieSameSiteStrict , kv . value ) {
426
+ if caseInsensitiveCompare (strCookieSameSiteStrict , c . bufV ) {
428
427
c .sameSite = CookieSameSiteStrictMode
429
428
}
430
429
case 'n' : // "none"
431
- if caseInsensitiveCompare (strCookieSameSiteNone , kv . value ) {
430
+ if caseInsensitiveCompare (strCookieSameSiteNone , c . bufV ) {
432
431
c .sameSite = CookieSameSiteNoneMode
433
432
}
434
433
}
435
434
}
436
435
}
437
436
}
438
- } else if len (kv . value ) != 0 {
437
+ } else if len (c . bufV ) != 0 {
439
438
// Case insensitive switch on first char
440
- switch kv . value [0 ] | 0x20 {
439
+ switch c . bufV [0 ] | 0x20 {
441
440
case 'h' : // "httponly"
442
- if caseInsensitiveCompare (strCookieHTTPOnly , kv . value ) {
441
+ if caseInsensitiveCompare (strCookieHTTPOnly , c . bufV ) {
443
442
c .httpOnly = true
444
443
}
445
444
446
445
case 's' : // "secure"
447
- if caseInsensitiveCompare (strCookieSecure , kv . value ) {
446
+ if caseInsensitiveCompare (strCookieSecure , c . bufV ) {
448
447
c .secure = true
449
- } else if caseInsensitiveCompare (strCookieSameSite , kv . value ) {
448
+ } else if caseInsensitiveCompare (strCookieSameSite , c . bufV ) {
450
449
c .sameSite = CookieSameSiteDefaultMode
451
450
}
452
451
case 'p' : // "partitioned"
453
- if caseInsensitiveCompare (strCookiePartitioned , kv . value ) {
452
+ if caseInsensitiveCompare (strCookiePartitioned , c . bufV ) {
454
453
c .partitioned = true
455
454
}
456
455
}
@@ -507,7 +506,7 @@ func parseRequestCookies(cookies []argsKV, src []byte) []argsKV {
507
506
s .b = src
508
507
var kv * argsKV
509
508
cookies , kv = allocArg (cookies )
510
- for s .next (kv ) {
509
+ for s .next (& kv . key , & kv . value ) {
511
510
if len (kv .key ) > 0 || len (kv .value ) > 0 {
512
511
cookies , kv = allocArg (cookies )
513
512
}
@@ -519,7 +518,7 @@ type cookieScanner struct {
519
518
b []byte
520
519
}
521
520
522
- func (s * cookieScanner ) next (kv * argsKV ) bool {
521
+ func (s * cookieScanner ) next (key , val * [] byte ) bool {
523
522
b := s .b
524
523
if len (b ) == 0 {
525
524
return false
@@ -532,23 +531,23 @@ func (s *cookieScanner) next(kv *argsKV) bool {
532
531
case '=' :
533
532
if isKey {
534
533
isKey = false
535
- kv . key = decodeCookieArg (kv . key , b [:i ], false )
534
+ * key = decodeCookieArg (* key , b [:i ], false )
536
535
k = i + 1
537
536
}
538
537
case ';' :
539
538
if isKey {
540
- kv . key = kv . key [:0 ]
539
+ * key = ( * key ) [:0 ]
541
540
}
542
- kv . value = decodeCookieArg (kv . value , b [k :i ], true )
541
+ * val = decodeCookieArg (* val , b [k :i ], true )
543
542
s .b = b [i + 1 :]
544
543
return true
545
544
}
546
545
}
547
546
548
547
if isKey {
549
- kv . key = kv . key [:0 ]
548
+ * key = ( * key ) [:0 ]
550
549
}
551
- kv . value = decodeCookieArg (kv . value , b [k :], true )
550
+ * val = decodeCookieArg (* val , b [k :], true )
552
551
s .b = b [len (b ):]
553
552
return true
554
553
}
0 commit comments