我們正在將位置標題從IIS反向代理重寫邏輯到IBM dataPower XI52 ..我知道我們有DP上的標題重寫功能,但我無法理解我們可以在DP上實施下面的場景,你能指導我嗎?我可以知道什麼是R:1,R:2和R:3是指這裏?在IIS反向代理 位置HeaderRewrite傳出規則:HTTP位置標題重寫 - 從IIS代理移動邏輯到IBM datapower
<rule name="Change Location Header" enabled="true">
<match serverVariable="RESPONSE_LOCATION" pattern="^http(s)?://([^/]+)/(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="true">
<add input="{RESPONSE_STATUS}" pattern="^301" />
<add input="{RESPONSE_STATUS}" pattern="^302" />
</conditions>
<action type="Rewrite" value="http{R:1}://{R:2}/{R:3}" />
</rule>
我想知道我們如何才能實現對DP一樣嗎?
我試過使用下面的xslt,但得到空的LocationHeader_output值,我在這裏做錯了什麼?
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions"
xmlns:re="http://exslt.org/regular-expressions"
extension-element-prefixes="dp re"
exclude-result-prefixes="dp">
<xsl:template match="*">
<xsl:choose>
<xsl:when test="dp:responding()">
<xsl:variable name="code">
<xsl:choose>
<xsl:when test="dp:http-response-header('x-dp-response-code') != ''">
<xsl:value-of select="substring(dp:http-response-header('x-dp-response-code'), 1, 3)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring(dp:variable('var://service/error-headers'), 10, 3)" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$code = '301' or $code = '302'">
<xsl:variable name="location" select="dp:http-response-header('Location')"/>
<xsl:variable name="location_final">
<xsl:value-of select="re:replace($location, '^http(s)?://([^/]+)/(.*)', 'g', 'http{$1}://{$2}/{$3}')" />
</xsl:variable>
<dp:set-http-response-header name="'Location'" value="$location_final" />
</xsl:if>
<!-- the following prevent DataPower from overriding the response code coming back from Server-->
<dp:set-response-header name="'x-dp-response-code'" value="'-1'"/>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:template>