tml-http

TML http support

npm install tml-http
4 downloads in the last week
8 downloads in the last month

tml-mongo(3) -- http (express) support

SYNOPSIS

tml-http http (express) support.

OPTIONS

SYNTAX

ENVIRONMENT

RETURN VALUES

STANDARDS

SECURITY CONSIDERATIONS

BUGS

HISTORY

AUTHOR

SEE ALSO

IMPLEMENTATION


Http

@purpose HTTP (express) support;
@author Erin Phillips;
@version 0.0.1-2;
    @history 2013-04-30 EMP [0.0.1-1] add-tml-build;
    @history 2013-04-30 EMP [0.0.1-2] remove-resource-client;

resources

TMLR = tml-runtime [TmlRuntime] @purpose Core TMLR runtime;

CON = console

locals

log = CON::log stringifyJson = TMLR::json parseJson = TMLR::parseJson

code

-- PATTERNS --;

pattern patMakeCookie :n

    <<<
    ##anvil make:n %Request name$ opt life# -> ret%:n
        vars v=coalesce a.get:n(name) {};;
        if noval a.get:n(name)
            log(con 'no :n named `' name '`');
        ret=(new :n(name,life)).set(v);
    >>>

-- STATICS --;

render patMakeCookie SignedCookie;

render patMakeCookie UnsignedCookie;

render patMakeCookie ClientCookie;

-- TYPES --;

    @values={}
    @signed=true
    @httpOnly=true;

method get -> %

    =@values;

method getName -> $

    =@name;

method getValue $ -> ?

    =coalesce @values.(a) '';;

method getNumericValue $ ->

    =coalesce as-numeric @values.(a) 0;;    

method set % -> this

    @values=a;

method setHttpOnly ! -> this

    @httpOnly=a;

method setSigned ! -> this

    @signed=a;

method setValue $ ? -> this

    @values.(a)=b;

method getTtlMillis ->

    =@ttlMillis;

method getProps -> %

    ={}
    if gt @ttlMillis 0 a.maxAge=@ttlMillis;
    if @signed a.signed=true;
    if @httpOnly a.httpOnly=true;;

method incValue $ -> this

    vars v=coalesce @values.(a) 0;;
    inc v
    @values.(a)=v;

method decValue $ -> this

    vars v=coalesce @values.(a) 0;;
    dec v
    @values.(a)=v;

type SignedCookie(name$,ttlMillis#=0)

    extends Cookie(name,ttlMillis)

type UnsignedCookie(name$,ttlMillis#=0)

    extends Cookie(name,ttlMillis)
    @setSigned(false);

type ClientCookie(name$,ttlMillis#=0)

    extends Cookie(name,ttlMillis)
    @setSigned(false)
    @setHttpOnly(false);

type Request(@h%)

method getSignedCookie $ -> opt %

    =@h.signedCookies.(a);

method deleteSignedCookie $ -> this

    delete @h.signedCookies.(a);

method getClientCookie $ -> opt %

    =@h.cookies.(a)
    if (b and isa b $)
        b=parseJson(b);;

method deleteCookie $ -> this

    delete @h.cookies.(a);

method getQueryNumber $ -> opt

    =@h.query.(a)
    ifnot noval b
        b=as-numeric b;;

method getQueryValue $ -> opt $

    =@h.query.(a);

method getFormValue $ -> opt $

    =@h.body.(a);

type Result(@h%)

    @h.cookie(a.getName(),a.get(),a.getProps());

method clearCookie name$ -> this

    @h.clearCookie(name);
npm loves you