BBjCookie::isHttpOnly

Description

In BBj 18.04 and higher, this method returns true if the cookie can only be sent over HTTP.

Syntax

Return Value

Method

boolean

isHttpOnly()

Parameters

None.

Return Value

Returns a boolean where 0 = BBjCookie is not only for secure connections and 1 = BBjCookie is only for secure connections.

Remarks

HttpOnly is an additional flag included in a Set-Cookie HTTP response header. Using the HttpOnly flag when generating a cookie helps mitigate the risk of client side script accessing the protected cookie (if the browser supports it).

Example

CLASS PUBLIC CookieExampleServlet 
    method public void service(BBxServletContext context!) 
       
        request! = context!.getRequest()
        response! = context!.getResponse()
        session! = request!.getSession()

        s! = response!.getOutputStream()
        s!.write("<html><body>")
        
        cookies! = request!.getCookies()
        sz = cookies!.size()
        IF (sz) THEN
            s!.write("<ul>")
            FOR i = 0 TO sz-1
                cookie! = cookies!.get(i)
                s!.write("<li>")
                s!.write("The BBjCookie '" + cookie!.getName() + "' ")
                s!.write("has the value '" + cookie!.getValue() + "' ")
                
                domain! = cookie!.getDomain()
                IF domain! = NULL() THEN
                    domain! = "null"
                ENDIF
                
                path! = cookie!.getPath()
                IF path! = NULL() THEN
                    path! = "null"
                ENDIF
                
                s!.write("for the domain " + domain! + " ")
                s!.write("at path " + path! + " ")
                s!.write("will expire in " + Integer.toString(cookie!.getMaxAge()) + " seconds ")
                
                IF cookie!.getSecure() THEN
                    s!.write(" for HTTPS protocol ")
                ENDIF

                IF cookie!.isHttpOnly() THEN
                    s!.write(" only for HTTP protocol ")
                ENDIF
                
                s!.write("is version " + Integer.toString(cookie!.getVersion()) + " ")
                
                IF cookie!.getComment() <> NULL() THEN
                    s!.write("comment '" + cookie!.getComment() + "' ")
                ENDIF
                
            NEXT i
            s!.write("</ul>")
        ENDIF
        s!.write("</body></html>")
    METHODEND
CLASSEND

See Also

BBjAPI

BBxServletContext

BBxServletResponse

BBxServletRequest

BBjCookie