rwf2/Rocket

Lack of handling for CORS/OPTIONS

开放

#25 创建于 2016年12月23日

 (33 条评论) (20 个反应) (0 位负责人)Rust (1,645 个派生)batch import
acceptedenhancementhelp wantedrequest

仓库指标

星标
 (25,738 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

In order for a server to provide an external API it needs to be able to deal with Cross Origin Resource Sharing. These are done by web browsers sending a preflight OPTIONS request asking what resources it is allowed to access on the server, then after being given a resonse containing certain information in it's header a browser will send the actual GET/PUT/POST/etc query to the server, with no response it will not do this and cause Cross Site Scripting errors to be reported.

There are two obvious ways this can be handled, the first and simplest is to add an "OPTIONS" annotation of the same ilk as the existing HTTP Methods, this will allow users of Rocket to manually implement the correct preflight request handling for api endpoints that need to provide CORS.

The other is to provide some form of automatic CORS handling, this can be seen in a number of other libraries used for web server development (outside the realm of rust) such as spring.io (http://docs.spring.io/spring/docs/current/spring-framework-reference/html/cors.html) or flasks (https://pypi.python.org/pypi/Flask-Cors).

W3 Specification on CORS: https://www.w3.org/TR/cors/

贡献者指南