Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

22
LINES

< > BotCompany Repo | #1011963 // serveHttp_cookieHandling

JavaX fragment (include)

static int serveHttp_cookieHandling_defaultDays = 365;
static S serveHttp_cookieHandling_defaultCookieName = "cookie";
sbool serveHttp_cookieHandling_verbose;

// returns cookie (may be empty if client doesn't accept cookies)
static S serveHttp_cookieHandling() {
  NanoHTTPD.IHTTPSession session = NanoHTTPD.currentSession.get();
  NanoHTTPD.CookieHandler cookies = session.getCookies();
  S cookie = cookies.read("cookie");
  if (cookie == null) {
    if (empty((S) mapGet(MyHTTPD_headers!, "x-no-cookies"))) {
      cookie = randomID(20);
      if (serveHttp_cookieHandling_verbose)
        print("New cookie.");
    }
  }
  if (serveHttp_cookieHandling_verbose)
    print("Cookie: " + cookie);
  if (nempty(cookie))
    cookies.set("cookie", cookie, serveHttp_cookieHandling_defaultDays);
  ret cookie; 
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1011963
Snippet name: serveHttp_cookieHandling
Eternal ID of this version: #1011963/2
Text MD5: 78f87f9bf8ca3767cfe192cf723a5c18
Author: stefan
Category: eleu / javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-11-14 00:20:26
Source code size: 830 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 472 / 522
Version history: 1 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1027732 - ServeHttp_CookieHandler