Cookie

public struct Cookie

A representation of an HTTP cookie.

  • The name of the cookie.

    Declaration

    Swift

    public var name: String
  • The cookie’s string value.

    Declaration

    Swift

    public var value: String
  • The cookie’s path.

    Declaration

    Swift

    public var path: String
  • The domain of the cookie.

    Declaration

    Swift

    public var domain: String?
  • The cookie’s expiration date.

    Declaration

    Swift

    public var expires: Date?
  • The cookie’s age in seconds.

    Declaration

    Swift

    public var maxAge: Int?
  • Whether the cookie should only be sent to HTTP servers.

    Declaration

    Swift

    public var httpOnly: Bool
  • Whether the cookie should only be sent over secure channels.

    Declaration

    Swift

    public var secure: Bool
  • Create a Cookie by parsing a Set-Cookie header.

    Declaration

    Swift

    public init?(header: String, defaultDomain: String)

    Parameters

    header

    String representation of the Set-Cookie response header.

    defaultDomain

    Default domain to use if cookie was sent without one.

    Return Value

    nil if the header is invalid.

  • Create HTTP cookie.

    Declaration

    Swift

    public init(name: String, value: String, path: String = "/", domain: String? = nil, expires: Date? = nil, maxAge: Int? = nil, httpOnly: Bool = false, secure: Bool = false)

    Parameters

    name

    The name of the cookie.

    value

    The cookie’s string value.

    path

    The cookie’s path.

    domain

    The domain of the cookie, defaults to nil.

    expires

    The cookie’s expiration date, defaults to nil.

    maxAge

    The cookie’s age in seconds, defaults to nil.

    httpOnly

    Whether this cookie should be used by HTTP servers only, defaults to false.

    secure

    Whether this cookie should only be sent using secure channels, defaults to false.