Examples using com.HTTPServiceRequest methods

These examples use methods of the com.HTTPServiceRequest class.

Server-side example

IMPORT COM
IMPORT Security
IMPORT FGL WSHelper

CONSTANT C_5_MINUTES  = INTERVAL(5) MINUTE TO MINUTE

MAIN
  DEFINE  expires  DATETIME DAY TO SECOND  
  DEFINE  req      com.HTTPServiceRequest
  DEFINE  query    WSHelper.WSQueryType
  DEFINE  ind      INTEGER
  DEFINE  url, host, port, path, myCookie STRING
  DEFINE  cookies  WSHelper.WSServerCookiesType
  
  CALL com.WebServiceEngine.Start()
  WHILE true
    LET req = com.WebServiceEngine.GetHTTPServiceRequest(-1)
    LET url = req.getURL()
    DISPLAY "URL is :",url
    LET host = req.getURLHost()
    DISPLAY "Host is :",host      
    LET port = req.getURLPort()
    DISPLAY "Port is :",port      
    LET path = req.getURLPath()
    DISPLAY "Path is :",path      
    CALL req.getURLQuery(query)
    FOR ind = 1 TO query.getLength()
      DISPLAY "Query "||ind
      DISPLAY "  key =",query[ind].name
      DISPLAY "  val = ",query[ind].value
    END FOR

    # Set the response character set       
    CALL req.setResponseCharset("UTF-8") 

    LET myCookie = req.findRequestCookie("UserIDCookie")
    IF myCookie IS NULL THEN
      DISPLAY "New user"
    ELSE
      DISPLAY "User id is :",myCookie
    END IF      

    # Compute Set-Cookies
    DISPLAY "Now is :",CURRENT
    LET expires = CURRENT + C_5_MINUTES
      
    LET cookies[1].name = "AnotherCookie"
    LET cookies[1].value= "security.RandomGenerator.CreateUUIDString()"
    LET cookies[1].domain = ".strasbourg.4js.com"
    LET cookies[1].expires = expires
    LET cookies[1].httpOnly = TRUE
    CALL req.setResponseCookies(cookies)
    # Send response with cookie 
    CALL req.sendTextResponse(200,NULL,"IT WORKS.")
  END WHILE   
END MAIN