Setting origin or referer value which from request to the response-header using urlrewritefilter

被刻印的时光 ゝ 提交于 2019-12-12 03:39:39

问题


How to set origin value or referer value in a response-header using tuckey url rewrite filter xml file.

Accessing %{origin} directly in the set tag is not working but not working in condition tag.

Below is the example I tried.

    <rule enabled="true" last="false" match-type="regex">
    <name>Enabling CORS Headers</name>
    <from>^/path/someMorePath.*$</from>
    <condition name="origin" operator="equal">http://www.testsite.com</condition> <!-- would like to write some regex to match a set of sites and if matched, then set the same origin as response -->
    <set type="response-header" name="Access-Control-Allow-Origin">%{origin}</set>
    <set type="response-header" name="Access-Control-Allow-Credentials">true</set>
</rule>

回答1:


After having an complete understanding on the urlrewritefilter of tuckey api, the solution is to have a regular expression.

<rule enabled="true" match-type="regex">
    <name>Enabling CORS Headers</name>
    <from>^/path/someMorePath.*$</from>
    <condition name="origin" operator="equal">([a-z.\/\/0-9]+)</condition>
    <set type="response-header" name="Access-Control-Allow-Origin">%1</set>
    <set type="response-header" name="Access-Control-Allow-Credentials">true</set>
</rule>

So, here using the regular expression in the condition tag and then using the back references in the regular expression as the variables in the response header



来源:https://stackoverflow.com/questions/43553224/setting-origin-or-referer-value-which-from-request-to-the-response-header-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!