gpt4 book ai didi

骡子 ESB : Filter based on HTTP method

转载 作者:行者123 更新时间:2023-12-02 05:03:57 25 4
gpt4 key购买 nike

我想知道是否有一种方法可以根据 HTTP 方法过滤/路由消息。我要做的是不处理使用 OPTIONS 方法发布的传入请求。 (这是为了跨源资源共享处理)

最佳答案

您可以使用 MEL(Mule Exression Language - http://www.mulesoft.org/documentation/display/current/Mule+Expression+Language+MEL)来查询 http.method 参数和选择路由器,如果您想对 OPTIONS 请求执行某些操作,例如发回允许的方法,如下所示:

<choice doc:name="Choice">
<when expression="#[message.inboundProperties['http.method'] == 'OPTIONS']">
<http:response-builder status="200"
doc:name="HTTP Response Builder(200 - OPTIONS)">
<http:header name="Allow" value="GET" />
<http:header name="Content-Type" value="#[null]" />
<set-payload value="#[null]" />
</http:response-builder>
</when>
<otherwise>
<!-- Do something else -->

</oherwise>
</choice>

或者,如果您只想删除消息,则可以使用表达式过滤器,如果不是选项:

<expression-filter
expression="#[message.inboundProperties['http.method'] != 'OPTIONS']" />

这里有更多关于路由和过滤的信息:

http://www.mulesoft.org/documentation/display/current/Routing+Message+Processors

http://www.mulesoft.org/documentation/display/current/Using+Filters

关于骡子 ESB : Filter based on HTTP method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16560299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com