GAE CGI:如何响应http状态代码
我正在使用googleappening,它是CGI环境。我想阻止一些请求,我不想响应任何内容,甚至没有 http 状态代码。或者,我只想关闭连接。我可以这样做吗?
更新:
我决定使用 pyfunc 所说的,使用 204 状态,但是我如何在 GAE CGI 环境没有任何网络框架的情况下做到这一点。
更新 2:
非常感谢,但是......我真的需要CGI 方式,而不是 WSGI 方式。请参阅我的代码中的评论。
def main()
#Block requests at once.
if (settings.BLOCK_DOWNLOAD and os.environ.get('HTTP_RANGE')) \
or (settings.BLOCK_EXTENSION.match(os.environ['PATH_INFO'])):
#TODO: return 204 response in CGI way.
#I really do not need construct a WSGIApplication and then response a status code.
return
application = webapp.WSGIApplication([
(r'/', MainHandler),
#...
], debug=True)
run_wsgi_app(application)
if __name__ == '__main__':
main()
I am using google appening, it's CGI environment. I want block some request, I want response nothing even no http status code. Alternative, I want just close the connection. Can I do this?
update:
I have decide to use what pyfunc said, use 204 status, but how can I do this at GAE CGI environment without any webframework.
update 2:
Thanks a lot, but... I really need a CGI way, not WSGI way. Please see the comment in my codes.
def main()
#Block requests at once.
if (settings.BLOCK_DOWNLOAD and os.environ.get('HTTP_RANGE')) \
or (settings.BLOCK_EXTENSION.match(os.environ['PATH_INFO'])):
#TODO: return 204 response in CGI way.
#I really do not need construct a WSGIApplication and then response a status code.
return
application = webapp.WSGIApplication([
(r'/', MainHandler),
#...
], debug=True)
run_wsgi_app(application)
if __name__ == '__main__':
main()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[编辑:更新的问题]
您可以查看许多用 GAE 标记的 SO 示例:
据我了解,您将使用 webapp 框架。加强它的使用。
中查看如何设置响应对象状态代码
下面是一个简单服务器的示例,它响应 204 no content。我还没有测试过它,但它会是类似的。
请访问以下网址查看完整的申请:
[Edit: updated question]
You can look at many a examples on SO tagged with GAE:
It is my understanding that you will be using webapp framework. Beef up on it's usage.
Check how to set response object status code at
Here is an example of bare bone server that responds with 204 no content. I have not tested it, but it would be in similar lines.
See a complete application at :