-
Notifications
You must be signed in to change notification settings - Fork 272
/
HTTPCookie.scala
109 lines (93 loc) · 3.68 KB
/
HTTPCookie.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Copyright 2007-2011 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.liftweb
package http
package provider
import net.liftweb.common.{Box, Empty, Full}
object SameSite extends Enumeration {
val LAX, STRICT, NONE = Value
}
/**
* Companion module for creating HTTPCookie objects
*/
object HTTPCookie {
def apply(name: String, value: String) = new HTTPCookie(name, Full(value), Empty, Empty, Empty, Empty, Empty)
}
/**
* Repersents an immutable representation of an HTTP Cookie
*/
case class HTTPCookie(name: String,
value: Box[String],
domain: Box[String],
path: Box[String],
maxAge: Box[Int],
version: Box[Int],
secure_? : Box[Boolean],
httpOnly: Box[Boolean] = Empty,
sameSite : Box[SameSite.Value] = Empty) extends java.lang.Cloneable {
override def clone(): HTTPCookie = {
super.clone()
copy()
}
/**
* Returns a new HTTPCookie that preserve existing member values but sets the httpOnly attribute
* @param flagHttpOnly - should the cookie be flagged as HTTP Only
* @return HTTPCookie
*/
def setHttpOnly(flagHttpOnly: Boolean): HTTPCookie = copy(httpOnly = Full(flagHttpOnly))
/**
* Returns a new HTTPCookie that preserve existing member values but sets the sameSite attribute
* @param newSameSite - the new cookie SameSite value
* @return HTTPCookie
*/
def setSameSite(newSameSite: SameSite.Value): HTTPCookie = copy(sameSite = Full(newSameSite))
/**
* Returns a new HTTPCookie that preserve existing member values but sets the cookie value to newValue
* @param newValue - the new cookie value
* @return HTTPCookie
*/
def setValue(newValue: String): HTTPCookie = copy(value = Box !! newValue)
/**
* Returns a new HTTPCookie that preserve existing member values but sets the cookie domain to newDomain
* @param newDomain - the new cookie domain
* @return HTTPCookie
*/
def setDomain(newDomain: String): HTTPCookie = copy(domain = Box !! newDomain)
/**
* Returns a new HTTPCookie that preserve existing member values but sets the cookie path to newPath
* @param newPath - the new cookie path
* @return HTTPCookie
*/
def setPath(newPath: String): HTTPCookie = copy(path = Box !! newPath)
/**
* Returns a new HTTPCookie that preserve existing member values but sets the cookie maxAge to newVMaxAge
* @param newMaxAge - the new cookie maxAge
* @return HTTPCookie
*/
def setMaxAge(newMaxAge: Int): HTTPCookie = copy(maxAge = Box !! newMaxAge)
/**
* Returns a new HTTPCookie that preserve existing member values but sets the cookie version to newVersion
* @param newVersion - the new cookie version
* @return HTTPCookie
*/
def setVersion(newVersion: Int): HTTPCookie = copy(version = Box !! newVersion)
/**
* Returns a new HTTPCookie that preserve existing member values but sets the cookie secure flag to newSecure
* @param newSecure - the new cookie secure flag
* @return HTTPCookie
*/
def setSecure(newSecure: Boolean): HTTPCookie = copy(secure_? = Box !! newSecure)
}