Vapor Documentation

Structure HTTPCookies.​Value

public struct Value: ExpressibleByStringLiteral  

A single cookie (key/value pair).

%599 HTTPCookies.Value HTTPCookies.Value ExpressibleByStringLiteral ExpressibleByStringLiteral HTTPCookies.Value->ExpressibleByStringLiteral

Member Of

HTTPCookies

A collection of HTTPCookies.

Conforms To

ExpressibleByStringLiteral

Initializers

init(string:​expires:​max​Age:​domain:​path:​is​Secure:​is​HTTPOnly:​same​Site:​)

public init(
            string: String,
            expires: Date? = nil,
            maxAge: Int? = nil,
            domain: String? = nil,
            path: String? = "/",
            isSecure: Bool = false,
            isHTTPOnly: Bool = false,
            sameSite: SameSitePolicy? = .lax
        )  

Creates a new HTTPCookieValue.

let cookie = HTTPCookieValue(string: "123")

Parameters

value

Value for this cookie.

expires Date?

The cookie's expiration date. Defaults to nil.

max​Age Int?

The maximum cookie age in seconds. Defaults to nil.

domain String?

The affected domain at which the cookie is active. Defaults to nil.

path String?

The path at which the cookie is active. Defaults to "/".

is​Secure Bool

Limits the cookie to secure connections. If sameSite is none, this flag will be overridden with true. Defaults to false.

is​HTTPOnly Bool

Does not expose the cookie over non-HTTP channels. Defaults to false.

same​Site Same​Site​Policy?

See HTTPSameSitePolicy. Defaults to lax.

init(string​Literal:​)

public init(stringLiteral value: String)  

See ExpressibleByStringLiteral.

Properties

expired

public static let expired: Value  

An expired HTTPCookieValue.

string

public var string: String

The cookie's value.

expires

public var expires: Date? 

The cookie's expiration date

max​Age

public var maxAge: Int? 

The maximum cookie age in seconds.

domain

public var domain: String? 

The affected domain at which the cookie is active.

path

public var path: String? 

The path at which the cookie is active.

is​Secure

public var isSecure: Bool

Limits the cookie to secure connections.

is​HTTPOnly

public var isHTTPOnly: Bool

Does not expose the cookie over non-HTTP channels.

same​Site

public var sameSite: SameSitePolicy? 

A cookie which can only be sent in requests originating from the same origin as the target domain.

This restriction mitigates attacks such as cross-site request forgery (XSRF).

Methods

serialize(name:​)

public func serialize(name: String) -> String  

Seriaizes an HTTPCookie to a String.