python cherrypy - как добавить заголовок - PullRequest
9 голосов
/ 19 мая 2011

Как добавить заголовок повторения в cherrypy?

  import cherrypy
  import os

  class Root:

    def index(self):
      cherrypy.response.headers['Retry-After'] = 60
      cherrypy.request.headers["Age"]= 20
      cherrypy.config.update({'Retry-After': '60'})

      raise cherrypy.HTTPError(503, 'Service Unavailable')
    index.exposed = True 

    cherrypy.quickstart(Root())

Этот повторный заголовок dt работает.

1 Ответ

21 голосов
/ 19 мая 2011

Когда вы устанавливаете код состояния путем увеличения HTTPError, заголовки в cherrypy.response.headers игнорируются. Установите статус HTTP, установив cherrypy.response.status вместо:

import cherrypy

class Root:
    def index(self):
        cherrypy.response.headers['Retry-After'] = 60
        cherrypy.response.status = 503
        # Feel free to return a better error page than the following
        return "<h1>Service Unavailable</h1>"
    index.exposed = True

cherrypy.quickstart(Root())
...