forked from ctb/cse491-serverz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookieapp.py
30 lines (27 loc) · 1.11 KB
/
cookieapp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def wsgi_app(env, start_response):
path = env['PATH_INFO']
if path == '/':
cookie_info = env.get('HTTP_COOKIE', "")
cookie_info = "The cookie sez: %s<p>" % cookie_info
start_response('200 OK', [('Content-type', 'text/html')])
return [cookie_info,
"<a href='/set'>Set cookie</a> | ",
"<a href='/del'>Clear cookie</a>"]
elif path == '/set':
start_response('302 Redirect', [('Content-type', 'text/html'),
('Location', '/'),
('Set-Cookie', 'favorite_color=red')
])
return ["You should have been redirected"]
elif path == '/del':
start_response('302 Redirect', [('Content-type', 'text/html'),
('Location', '/'),
('Set-Cookie', 'favorite_color=NONE; Expires=Thu, 01-Jan-1970 00:00:01 GMT')
])
return ["You should have been redirected"]
start_response('404 Not Found', [('Content-type', \
'text/html; \
charset="UTF-8"')])
return []
def get_wsgi_app():
return wsgi_app