Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
shrapnel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
shrapnel
Commits
6e921736
Commit
6e921736
authored
Mar 27, 2012
by
Sam Rushing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simple session demo
parent
e6d0749f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
0 deletions
+45
-0
coro/http/demo/session.py
coro/http/demo/session.py
+45
-0
No files found.
coro/http/demo/session.py
0 → 100644
View file @
6e921736
# -*- Mode: Python -*-
import
coro
import
coro.http
import
backdoor
# demonstrate the session handler
import
sys
W
=
sys
.
stderr
.
write
def
session
(
sid
,
fifo
):
i
=
0
while
1
:
try
:
# wait a half hour for a new hit
request
=
coro
.
with_timeout
(
1800
,
fifo
.
pop
)
except
coro
.
TimeoutError
:
break
else
:
request
[
'content-type'
]
=
'text/html'
if
i
==
10
:
request
.
push
(
'<html><h1>Session Over! Bye!</h1>'
'<a href="session">start over</a>'
'</html>'
)
request
.
done
()
break
else
:
request
.
push
(
'<html><h1>Session Demo</h1><br><h2>Hit=%d</h2>'
'<a href="session">hit me!</a>'
'</html>'
%
(
i
,)
)
request
.
done
()
i
+=
1
server
=
coro
.
http
.
server
()
server
.
push_handler
(
coro
.
http
.
handlers
.
coro_status_handler
())
server
.
push_handler
(
coro
.
http
.
session_handler
.
session_handler
(
'session'
,
session
))
server
.
push_handler
(
coro
.
http
.
handlers
.
favicon_handler
())
coro
.
spawn
(
server
.
start
,
(
'0.0.0.0'
,
9001
))
coro
.
spawn
(
backdoor
.
serve
,
unix_path
=
'/tmp/httpd.bd'
)
coro
.
event_loop
(
30.0
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment