2015-09-26 37 views
2

Spring 4.2 has CORS support,但是允許原點必須手動設置。與認證相結合時會出現問題,因爲認證不支持Access-Control-Allow-Origin: *如何在Spring Framework 4.2/Boot 1.3中基於Origin HTTP請求標頭設置動態Access-Control-Allow-Origin?

如何自動設置?對Ionic/Cordova客戶非常有用。

也就是說,如果客戶端發送Origin: assets-library://whatever/則服務器將發送Access-Control-Allow-Origin: assets-library://whatever/

功能要求:https://jira.spring.io/browse/SPR-13511

+0

我在JIRA問題的評論中回答了你,這應該已經被支持。 –

回答

1

由Spring啓動的 「默認」,春4.2不使用@CrossOriginaddCorsMappings()時支持我描述的場景。

什麼是不是默認,是通過使用Sébastien's technique described here(我已經更新了答案)。必須小心到:

config.setAllowCredentials(true); 

因爲真正默認的CorsConfiguration是它的null這被視爲false