pharaoh library

Functions

bakeCookie(String name, Object? value, CookieOpts opts) Cookie
bodyParser(Request req, Response res, NextFunction next) → dynamic
catchTopLevelErrors(void callback(), void onError(dynamic error, StackTrace)) → void
Run callback and capture any errors that would otherwise be top-leveled.
contentTypeToString(ContentType type, {String charset = 'utf-8'}) String
cookieParser({CookieOpts opts = const CookieOpts()}) Middleware
executeHandlers(Iterable handlers, ReqRes reqRes) Future<ReqRes>
getHttpMethod(HttpRequest req) HTTPMethod
hashData(dynamic sess) String
logRequests(Request req, Response res, NextFunction next) → dynamic
safeCompare(String a, String b) bool
sessionMdw({String name = Session.name, String? secret, bool saveUninitialized = true, bool rolling = false, bool resave = false, GenSessionIdFunc? genId, SessionStore? store, CookieOpts cookie = const CookieOpts(httpOnly: true, secure: false)}) Middleware
  • name The name of the session ID cookie to set in the response (and read from in the request). The default value is pharaoh.sid.

  • saveUninitialized Forces a session that is "uninitialized" to be saved to the store. A session is uninitialized when it is new but not modified. Default value is true

  • rolling The expiration is reset to the original maxAge, resetting the expiration countdown and forces the session identifier cookie to be set on every response.

  • resave Forces the session to be saved back to the session store, even if the session was never modified during the request. Default value is false

  • genId Function to call to generate a new session ID. Provide a function that returns a string that will be used as a session ID. Session ID is generated from uuid-v4 by default.

  • store The session store instance, defaults to a new MemoryStore instance.

  • cookie Settings object for the session ID cookie. The default value is { path: '/', httpOnly: true, secure: false, maxAge: null }.

  • secret This is the secret used to sign the session ID cookie. You can also provide it in cookie.secret options. But secret will will be used if both are set.

  • signValue(String value, String secret) String
    Sign the given value with secret.
    unsignValue(String input, String secret) String?
    Unsign and decode the given input with secret, returning null if the signature is invalid.
    useRequestHandler(RequestHandler handler) Middleware
    useShelfMiddleware(dynamic middleware) Middleware
    Use this hook to transform any shelf middleware into a Middleware that Pharaoh can use.

    Typedefs

    GenSessionIdFunc = FutureOr<String> Function(Request request)
    Middleware = FutureOr<void> Function(Request req, Response res, NextFunction next)
    NextFunction<Next> = dynamic Function([dynamic result, Next? chain])
    OnErrorCallback = FutureOr<Response> Function(PharaohError error, Request req, Response res)
    PharaohError = ({Object exception, StackTrace trace})
    ReqRes = ({Request req, Response res})
    ReqResHook = FutureOr<ReqRes> Function(ReqRes reqRes)
    RequestHandler = FutureOr Function(Request req, Response res)
    ShelfBody = Body
    ShelfMiddlewareType2 = FutureOr<Response> Function(Request)

    Exceptions / Errors

    PharaohException