Documentation
Sessions
WebSession.add_session
— Methodadd_session(session::Session)::Nothing
Add a session to the session storage.
Arguments
session
: the Session to be added.
Returns
The function returns nothing.
WebSession.add_session_data
— Functionadd_session_data(
key::String,
value::Union{String, Real},
req::HTTP.Request = Genie.Requests.request(),
res::HTTP.Response = Genie.Responses.getresponse()
)::Nothing
Add data to a session in the session storage.
Arguments
key
: the key of the data to be added.value
: the value of the data to be added.req
: the HTTP.Request object.res
: the HTTP.Response object.
Return
The function returns nothing.
WebSession.get_cookie
— Methodget_cookie(
payload::Union{HTTP.Request, HTTP.Response},
name::String
)::Union{HTTP.Cookie, Nothing}
Get a cookie from a HTTP.Request or HTTP.Response object.
Arguments
payload
: the HTTP.Request or HTTP.Response object.name
: the name of the cookie.
Return
The function returns the cookie if it exists, otherwise it returns nothing.
WebSession.get_session
— Methodget_session(
req::HTTP.Request,
res::HTTP.Response
)::Union{Session, Nothing}
Get a session from the session storage for a HTTP.Request and HTTP.Response object. If the session does not exist, it is created.
Arguments
req
: the HTTP.Request object.res
: the HTTP.Response object.
Return
The function returns the session if it exists, otherwise it returns the newly created.
WebSession.get_session_data
— Functionget_session_data(
key::String,
req::HTTP.Request = Genie.Requests.request(),
res::HTTP.Response = Genie.Responses.getresponse()
)::Union{Any, Nothing}
Gets the data for a session in the session store that matches the key.
Arguments
key
: the key of the data to be retrieved.req
: the HTTP.Request object. By default is Genie.Requests.request().res
: the HTTP.Response object. By default is Genie.Responses.getresponse().
Return
The function returns the data if it exists, otherwise it returns nothing.
WebSession.get_session_id
— Methodget_session_id(req::HTTP.Request, res::HTTP.Response)::Union{String, Nothing}
Get the session id from a HTTP.Request or HTTP.Response object. First will try to get the session id from the HTTP.Request object. If it does not exist, it will try to get it from the HTTP.Response object.
Arguments
req
: the HTTP.Request object.res
: the HTTP.Response object.
Return
The function returns the session id if it exists, otherwise it returns nothing.
WebSession.get_session_storage
— Methodget_session_storage(session_id::String)::Union{Session, Nothing}
Get a session from the session storage for a session id.
Arguments
session_id
: the session id.
Return
The function returns the session if it exists, otherwise it returns nothing.
WebSession.id
— Methodid()::String
Generates a random Session id.
Return
The function returns a random string Session id.
WebSession.remove_session
— Methodremove_session(session_id::String)::Nothing
Remove a session from the session storage.
Arguments
session_id
: the session id.
Return
The function returns nothing.
WebSession.session_exists
— Methodsession_exists(payload::Union{HTTP.Request, HTTP.Response})::Bool
Check if a session exists for a HTTP.Request or HTTP.Response object.
Arguments
payload
: the HTTP.Request or HTTP.Response object.
Return
The function returns true if the session exists, otherwise it returns false.
WebSession.start_session
— Methodstart_session(req::HTTP.Request, res::HTTP.Response)::Session
Starts a session to an HTTP.Request and HTTP.Response object. Checks if the session already exists and if it does, returns it. The cookie is set in the response. The session is added to the session store.
Arguments
req
: the HTTP.Request object.res
: the HTTP.Response object.
Return
The function returns the new session or an existing session.
Session Storage Management
WebSession.SessionStorageManagement
— MethodSessionStorageManagement()::Nothing
Manages the session storage. It's is a infinite loop that runs every 10 second. It checks if the session has expired and if it has, it removes it from the session storage. Don't need to call this function, it is called automatically by init() function and runs assyncronously.
Return
The function returns nothing.