# CherryPy / sphinx / source / progguide / customheaders.rst

Although the cherrypy.response.headers is usually adequate for supplying headers in a CherryPy response, it is sometimes desirable for the server application to customize the order of the resultant headers or provide multiple headers with duplicate keys. This section describes how one can accomplish these tasks within the CherryPy framework.

## Process

The CherryPy Response object maintains a dictionary of headers until the finalize phase, after which the headers in the dictionary are converted into a list of (name, value) tuples. See cherrypy._cprequest.Response for details.

Therefore, since a dictionary discards order and duplicate keys, customizing the order or duplicity of keys must occur after the finalize phase.

This end can be effected using a tool bound to the on_end_resource hook.

The following example illustrates the creation of a multiheaders tool to deliver multiple headers with the same key in the response.

#python
import cherrypy

class Root(object):
@cherrypy.expose
def index(self):
cherrypy.response.multiheaders = [('foo', '1'), ('foo', '2')]
return "Hello"

cherrypy.quickstart(Root())


The following example illustrates the creation of a firstheaders tool to deliver headers in a specified order (at the beginning) in the response.

#python
import cherrypy