()
| 475 | } |
| 476 | |
| 477 | func (s *Session) setSession() { |
| 478 | if s.ctx == nil { |
| 479 | return |
| 480 | } |
| 481 | |
| 482 | // Get all relevant extractors |
| 483 | relevantExtractors := s.getExtractorInfo() |
| 484 | |
| 485 | // Set session ID for each extractor type |
| 486 | for _, ext := range relevantExtractors { |
| 487 | switch ext.Source { |
| 488 | case extractors.SourceHeader: |
| 489 | s.ctx.Response().Header.SetBytesV(ext.Key, utils.UnsafeBytes(s.id)) |
| 490 | case extractors.SourceCookie: |
| 491 | fcookie := fasthttp.AcquireCookie() |
| 492 | |
| 493 | fcookie.SetKey(ext.Key) |
| 494 | fcookie.SetValue(s.id) |
| 495 | fcookie.SetPath(s.config.CookiePath) |
| 496 | fcookie.SetDomain(s.config.CookieDomain) |
| 497 | // Cookies are also session cookies if they do not specify the Expires or Max-Age attribute. |
| 498 | // refer: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie |
| 499 | if !s.config.CookieSessionOnly { |
| 500 | fcookie.SetMaxAge(int(s.idleTimeout.Seconds())) |
| 501 | fcookie.SetExpire(time.Now().Add(s.idleTimeout)) |
| 502 | } |
| 503 | |
| 504 | s.setCookieAttributes(fcookie) |
| 505 | s.ctx.Response().Header.SetCookie(fcookie) |
| 506 | fasthttp.ReleaseCookie(fcookie) |
| 507 | default: |
| 508 | // For non-cookie/header sources, do nothing (read-only) |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | func (s *Session) delSession() { |
| 514 | if s.ctx == nil { |
no test coverage detected