You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					47 lines
				
				1.1 KiB
			
		
		
			
		
	
	
					47 lines
				
				1.1 KiB
			| 
								 
											3 years ago
										 
									 | 
							
								'use strict'
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								module.exports = class Cookie {
							 | 
						||
| 
								 | 
							
								  constructor (cookieOpts) {
							 | 
						||
| 
								 | 
							
								    this.maxAge = cookieOpts.maxAge || null
							 | 
						||
| 
								 | 
							
								    this.path = cookieOpts.path || '/'
							 | 
						||
| 
								 | 
							
								    this.httpOnly = cookieOpts.httpOnly !== undefined ? cookieOpts.httpOnly : true
							 | 
						||
| 
								 | 
							
								    this.secure = cookieOpts.secure
							 | 
						||
| 
								 | 
							
								    this.expires = getExpires(cookieOpts)
							 | 
						||
| 
								 | 
							
								    this.sameSite = cookieOpts.sameSite || null
							 | 
						||
| 
								 | 
							
								    this.domain = cookieOpts.domain || null
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  options (secureConnection) {
							 | 
						||
| 
								 | 
							
								    let secure = this.secure
							 | 
						||
| 
								 | 
							
								    let sameSite = this.sameSite
							 | 
						||
| 
								 | 
							
								    if (secure === 'auto') {
							 | 
						||
| 
								 | 
							
								      if (secureConnection === true) {
							 | 
						||
| 
								 | 
							
								        secure = true
							 | 
						||
| 
								 | 
							
								      } else {
							 | 
						||
| 
								 | 
							
								        sameSite = 'Lax'
							 | 
						||
| 
								 | 
							
								        secure = false
							 | 
						||
| 
								 | 
							
								      }
							 | 
						||
| 
								 | 
							
								    } else {
							 | 
						||
| 
								 | 
							
								      secure = this.secure
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    return {
							 | 
						||
| 
								 | 
							
								      path: this.path,
							 | 
						||
| 
								 | 
							
								      httpOnly: this.httpOnly,
							 | 
						||
| 
								 | 
							
								      secure,
							 | 
						||
| 
								 | 
							
								      expires: this.expires,
							 | 
						||
| 
								 | 
							
								      sameSite,
							 | 
						||
| 
								 | 
							
								      domain: this.domain
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								function getExpires (cookieOpts) {
							 | 
						||
| 
								 | 
							
								  let expires = null
							 | 
						||
| 
								 | 
							
								  if (cookieOpts.expires) {
							 | 
						||
| 
								 | 
							
								    expires = cookieOpts.expires
							 | 
						||
| 
								 | 
							
								  } else if (cookieOpts.maxAge) {
							 | 
						||
| 
								 | 
							
								    expires = new Date(Date.now() + cookieOpts.maxAge)
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  return expires
							 | 
						||
| 
								 | 
							
								}
							 |