Commits

jaraco  committed 81adec5

Updated examples with working solution

  • Participants
  • Parent commits 378d0a8

Comments (0)

Files changed (2)

File 2454494/multiheaders.py

-    import httplib
-    from StringIO import StringIO
+import httplib
+from StringIO import StringIO
 
-    msg = \
-    """Set-Cookie: Foo
-    Set-Cookie: Bar
-    Set-Cookie: Baz
+msg = \
+"""Set-Cookie: Foo
+Set-Cookie: Bar
+Set-Cookie: Baz
 
-    This is the message"""
+This is the message"""
 
-    msg = StringIO(msg)
+msg = StringIO(msg)
 
-    msg = httplib.HTTPMessage(msg)
+msg = httplib.HTTPMessage(msg)
 
-    assert msg['Set-Cookie'] == 'Foo, Bar, Baz'
+assert msg['Set-Cookie'] == 'Foo, Bar, Baz'
+
+import urllib2
+u = urllib2.urlopen('http://localhost:8080')
+print u.headers['Foo']

File 2454494/server.py

 import cherrypy
 
-class HelloWorld(object):
+def multi_headers():
+	cherrypy.response.header_list.extend(cherrypy.response.multiheaders)
+
+cherrypy.tools.multiheaders = cherrypy.Tool('on_end_resource', multi_headers)
+
+class Root(object):
+	@cherrypy.expose
+	@cherrypy.tools.multiheaders()
 	def index(self):
-		cherrypy.response.header_list = [('Foo', 'foo'),('Foo', 'bar')]
-		cherrypy.response.headers['Baz'] = 'baz'
-		cherrypy.response.headers['Baz'] = 'boo'
-		return "Hello World!"
-	index.exposed = True
+		cherrypy.response.multiheaders = [('foo', '1'), ('foo', '2')]
+		return "Hello"
 
-cherrypy.quickstart(HelloWorld())
+cherrypy.quickstart(Root())