我当前正在将GAE与python和endpoints.api_server一起使用我可以从self.request state或os.environ获取标头,但在哪里可以添加自定义标头?我试图将jwt添加到头中,而不是将其传递到主体中,以便更容易地处理auth。
虽然比较晚,但我完成发回自定义响应标头的方法是将send_wsgi_response
封装在endpoints.util中
import endpoints.util as util
# Note: If someone imports send_wsgi_response before here, the function
# will NOT be decorated and the original function will be used until this bit runs
def add_headers(wsgi_func):
def wrapper(status, headers, content, start_response, cors_handler=None):
headers.append(('Some-Header', 'some-value'))
return wsgi_func(status, headers, content, start_response, cors_handler)
return wrapper
util.send_wsgi_response = add_headers(util.send_wsgi_response)
从此处复制并粘贴