Have the github pages source in the same branch.
This commit is contained in:
24
docs/workbook/handling_cookies/example/application.e
Normal file
24
docs/workbook/handling_cookies/example/application.e
Normal file
@@ -0,0 +1,24 @@
|
||||
note
|
||||
description: "Basic Service launcher"
|
||||
|
||||
class
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION]
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
|
||||
create
|
||||
make_and_launch
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
initialize
|
||||
-- Initialize current service.
|
||||
do
|
||||
set_service_option ("port", 9090)
|
||||
end
|
||||
|
||||
end
|
||||
141
docs/workbook/handling_cookies/example/application_execution.e
Normal file
141
docs/workbook/handling_cookies/example/application_execution.e
Normal file
@@ -0,0 +1,141 @@
|
||||
note
|
||||
description : "Basic Service that build a generic front to demonstrate the use of Cookies"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
APPLICATION_EXECUTION
|
||||
|
||||
inherit
|
||||
WSF_EXECUTION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute
|
||||
-- Execute the incomming request
|
||||
local
|
||||
l_message: STRING
|
||||
l_header: HTTP_HEADER
|
||||
l_time: HTTP_DATE
|
||||
l_cookies: STRING
|
||||
l_answer: STRING
|
||||
do
|
||||
-- all the cookies
|
||||
create l_cookies.make_empty
|
||||
across request.cookies as ic loop
|
||||
l_cookies.append (ic.item.name)
|
||||
l_cookies.append("<br>")
|
||||
end
|
||||
|
||||
if request.path_info.same_string ("/") then
|
||||
create l_header.make
|
||||
create l_answer.make_from_string (web_page)
|
||||
if request.cookie ("_EWF_Cookie") = Void then
|
||||
-- First access the the home page, find a cookie with specific name `_EWF_Cookie'
|
||||
l_answer.replace_substring_all ("$header_title", "Hey, thanks for access our cool site, this is your first acess")
|
||||
l_answer.replace_substring_all ("$cookies", l_cookies)
|
||||
create l_time.make_now_utc
|
||||
l_time.date_time.day_add (40)
|
||||
l_header.put_cookie_with_expiration_date ("_EWF_Cookie", "EXAMPLE",l_time.date_time, "", Void, False, True)
|
||||
else
|
||||
-- No a new access
|
||||
l_answer.replace_substring_all ("$header_title", "Welcome back, please check all the new things we have!!!")
|
||||
l_answer.replace_substring_all ("$cookies", l_cookies)
|
||||
end
|
||||
l_header.put_content_type_text_html
|
||||
l_header.put_content_length (l_answer.count)
|
||||
response.put_header_text (l_header.string)
|
||||
response.put_string (l_answer)
|
||||
|
||||
elseif request.path_info.same_string ("/visitors") then
|
||||
create l_header.make
|
||||
create l_answer.make_from_string (visit_page)
|
||||
if request.cookie ("_visits") = Void then
|
||||
-- First access the the visit page, find a cookie with specific name `_visits'
|
||||
l_answer.replace_substring_all ("$visit", "1")
|
||||
l_answer.replace_substring_all ("$cookies", l_cookies)
|
||||
create l_time.make_now_utc
|
||||
l_time.date_time.day_add (40)
|
||||
l_header.put_cookie_with_expiration_date ("_visits", "1",l_time.date_time, "/visitors", Void, False, True)
|
||||
|
||||
else
|
||||
if attached {WSF_STRING} request.cookie ("_visits") as l_visit then
|
||||
create l_time.make_now_utc
|
||||
l_time.date_time.day_add (40)
|
||||
l_answer.replace_substring_all ("$visit", (l_visit.value.to_integer + 1).out )
|
||||
l_answer.replace_substring_all ("$cookies", l_cookies)
|
||||
l_header.put_cookie_with_expiration_date ("_visits", (l_visit.value.to_integer + 1).out,l_time.date_time, "/visitors", Void, False, True)
|
||||
end
|
||||
end
|
||||
create l_time.make_now_utc
|
||||
l_time.date_time.second_add (120)
|
||||
l_header.put_content_type_text_html
|
||||
-- This cookie expires in 120 seconds, its valid for 120 seconds
|
||||
l_header.put_cookie_with_expiration_date ("_Framework", "EWF",l_time.date_time, "/", Void, False, True)
|
||||
-- This is a session cookie, valid only to the current browsing session.
|
||||
l_header.put_cookie ("Session", "Cookie",Void, "/", Void, False, True)
|
||||
l_header.put_content_length (l_answer.count)
|
||||
response.add_header_text (l_header.string)
|
||||
response.put_string (l_answer)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
feature -- Home Page
|
||||
|
||||
web_page: STRING = "[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>EWF Handling Cookies</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="right">
|
||||
<h2>$header_title</h2>
|
||||
</div>
|
||||
|
||||
<div class="right">
|
||||
<a href="/visitors">Visitors</a>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h3>Cookies for the home page</h3>
|
||||
$cookies
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
]"
|
||||
|
||||
|
||||
visit_page: STRING = "[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>EWF Handling Visit Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="right">
|
||||
<h2>The number of visits is $visit</h2>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h3>Cookies for the Visit page</h3>
|
||||
$cookies
|
||||
</div>
|
||||
</br>
|
||||
|
||||
<div>
|
||||
Back to <a href="/"> Home </a>
|
||||
</div>
|
||||
|
||||
<div id="footer">
|
||||
<p>EWF Example Cookies</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
]"
|
||||
|
||||
end
|
||||
42
docs/workbook/handling_cookies/example/example.ecf
Normal file
42
docs/workbook/handling_cookies/example/example.ecf
Normal file
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="example" uuid="C28C4F53-9963-46C0-A080-8F13E94E7486">
|
||||
<target name="common" abstract="true">
|
||||
<file_rule>
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
|
||||
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
|
||||
</target>
|
||||
<target name="example_standalone" extends="common">
|
||||
<root class="APPLICATION" feature="make_and_launch"/>
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<library name="default_standalone" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\standalone-safe.ecf"/>
|
||||
<cluster name="example" location=".\" recursive="true"/>
|
||||
</target>
|
||||
<target name="example_cgi" extends="common">
|
||||
<root class="APPLICATION" feature="make_and_launch"/>
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<library name="default_cgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\cgi-safe.ecf"/>
|
||||
<cluster name="example" location=".\" recursive="true"/>
|
||||
</target>
|
||||
<target name="example_libfcgi" extends="common">
|
||||
<root class="APPLICATION" feature="make_and_launch"/>
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<library name="default_libfcgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\libfcgi-safe.ecf"/>
|
||||
<cluster name="example" location=".\" recursive="true"/>
|
||||
</target>
|
||||
<target name="example" extends="example_standalone">
|
||||
</target>
|
||||
</system>
|
||||
Reference in New Issue
Block a user