MCPcopy
hub / github.com/gofiber/fiber / setSession

Method setSession

middleware/session/session.go:477–511  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

475}
476
477func (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
513func (s *Session) delSession() {
514 if s.ctx == nil {

Callers 1

Calls 7

getExtractorInfoMethod · 0.95
setCookieAttributesMethod · 0.95
SetPathMethod · 0.80
ResponseMethod · 0.65
AddMethod · 0.65
NowMethod · 0.45
SetCookieMethod · 0.45

Tested by

no test coverage detected