为消息处理器中的 405 属性配置忽略忽略标头

您正在查看 Apigee Edge 文档。
转到 Apigee X 文档
info

在客户端-服务器通信中,如果客户端提供的 HTTP 请求方法是服务器已知的,但目标资源不支持该方法,则服务器会返回 HTTP 状态代码 405 Method Not Allowed。同样,在 Apigee Edge 中,后端服务器可以 返回 HTTP 状态代码 405 Method Not Allowed.

Apigee Edge 预期后端服务器会根据规范 RFC 7231 第 6.5.5 节:405 不允许的方法,在 Allow 标头中发送包含允许的方法列表的 405 Method Not Allowed 响应。

Allow 标头必须采用以下格式发送:

Allow: HTTP_METHODS

例如,如果您的后端服务器允许 GETPOSTHEAD 方法,则需要确保 Allow 标头包含这些方法,如下所示:

Allow: GET, POST, HEAD

如果后端服务器未发送包含 HTTP 状态代码 405 Method Not Allowed,Allow 标头,则 Apigee 会向客户端应用返回 HTTP 状态代码 502 Bad Gateway,并返回错误代码 protocol.http.Response405WithoutAllowHeader 。解决此错误的推荐解决方案是 修复后端服务器,使其遵循规范 RFC 7231 第 6.5.5 节:405 不允许的方法,或者使用故障处理来 返回 HTTP 状态代码 405 Method Not Allowed,包括 Allow 标头,如故障排除手册 502 Bad Gateway - Response 405 without Allow header中所述。

不过,在某些特殊情况下,您可能无法立即修复后端或修改 API 代理来解决此问题。

在这种情况下,您可以暂时在消息处理器级别为 405 属性 HTTP.ignore.allow_header.for.405 设置忽略允许标头。将此属性设置为 true 可防止 Apigee 向客户端应用返回 502 Bad Gateway 响应,即使 后端服务器发送的 HTTP 状态代码 405 Method Not Allowed 不包含 Allow 标头也是如此。

当您能够修复后端服务器以发送包含 Allow 标头的 HTTP 状态代码 405 Method Not Allowed 时,可以将属性 HTTP.ignore.allow_header.for.405 恢复为其默认值 false

准备工作

在执行本文档中的步骤之前,请务必了解以下主题:

在消息处理器上将 405 属性的忽略允许标头配置为 true

在 Apigee Edge 中,属性 HTTP.ignore.allow_header.for.405 默认设置为 false。这样,如果后端服务器发送的 HTTP 状态代码 405 Method Not Allowed 不包含 Allow 标头,Apigee Edge 就会向 客户端应用返回 502 Bad Gateway,并返回错误代码 protocol.http.Response405WithoutAllowHeader。如果您想阻止 Apigee Edge 向客户端应用发送 502 Bad Gateway,则需要在消息处理器上将属性 HTTP.ignore.allow_header.for.405 的值设置为 true

本部分介绍了如何使用令牌(按照 如何配置 Edge中描述的语法)在消息处理器上将属性HTTP.ignore.allow_header.for.405配置为true

  1. 在消息处理器机器上,在编辑器中打开以下文件。如果该文件尚不存在,请创建它。

    /opt/apigee/customer/application/message-processor.properties

    例如,如需使用 vi 打开该文件,请输入以下内容:

    vi /opt/apigee/customer/application/message-processor.properties
  2. 将以下格式的一行添加到属性文件中:
    conf_http_HTTP.ignore.allow_header.for.405=true
  3. 保存更改。
  4. 确保属性文件的所有者是 apigee 用户,如下所示:
    chown apigee:apigee /opt/apigee/customer/application/message-processor.properties
    
  5. 重启消息处理器,如下所示:
    /opt/apigee/apigee-service/bin/apigee-service edge-message-processor restart
    
  6. 如果您有多个消息处理器,请在所有消息处理器上重复上述步骤。

验证消息处理器上是否已将 405 属性的忽略允许标头设置为 true

本部分介绍了如何验证消息处理器上是否已成功将属性 HTTP.ignore.allow_header.for.405 更新为 true

即使您使用令牌 conf_http_HTTP.ignore.allow_header.for.405 在消息处理器上更新属性的值,也需要验证实际属性 HTTP.ignore.allow_header.for.405 是否已设置为 true

  1. 在消息处理器机器上,在 /opt/apigee/edge-message-processor/conf 目录中搜索属性 HTTP.ignore.allow_header.for.405,并检查其是否已设置为 true,如下所示:
    grep -ri "HTTP.ignore.allow_header.for.405" /opt/apigee/edge-message-processor/conf
    
  2. 如果该属性在消息处理器上成功更新,则上述命令 应在 http.properties 文件中将属性 HTTP.ignore.allow_header.for.405 的值显示为 true,如下所示:
    /opt/apigee/edge-message-processor/conf/http.properties:HTTP.ignore.allow_header.for.405=true
  3. 如果您仍然看到属性 HTTP.ignore.allow_header.for.405 的值为 false,请验证您是否已正确按照在 消息处理器中将 405 属性的忽略允许标头配置为 true 中列出的所有步骤操作。如果您遗漏了任何步骤,请再次正确重复所有步骤。 正确。
  4. 如果您仍然无法修改属性 HTTP.ignore.allow_header.for.405,请与 Apigee Edge 支持团队联系

在消息处理器上将 405 属性的忽略允许标头配置为 false

本部分介绍了如何使用令牌(按照 如何配置 Edge中描述的语法)在消息处理器上将属性 HTTP.ignore.allow_header.for.405配置为其默认值 false

  1. 验证属性 HTTP.ignore.allow_header.for.405 是否已修改为 true。您可以在 /opt/apigee/edge-message-processor/conf 目录中搜索此属性,并使用以下命令检查其值:
    grep -ri "HTTP.ignore.allow_header.for.405" /opt/apigee/edge-message-processor/conf
    
  2. 如果该属性在消息处理器上设置为 true,则上述命令 应在 http.properties 文件中将属性 HTTP.ignore.allow_header.for.405 的值显示为 true,如下所示:
    /opt/apigee/edge-message-processor/conf/http.properties:HTTP.ignore.allow_header.for.405=true
  3. 如果上述命令显示属性 HTTP.ignore.allow_header.for.405 设置为 false(默认值),则无需执行任何其他操作。也就是说, 跳过以下步骤。
  4. 如果属性 HTTP.ignore.allow_header.for.405 设置为 true,请执行以下步骤以恢复为其默认值 false
  5. 在消息处理器机器上,在编辑器中打开以下文件:

    /opt/apigee/customer/application/message-processor.properties

    例如,如需使用 vi 打开该文件,请输入以下内容:

    vi /opt/apigee/customer/application/message-processor.properties
    
  6. 从属性文件中移除以下行:
    conf_http_HTTP.ignore.allow_header.for.405=true
  7. 保存更改。
  8. 确保属性文件的所有者是 apigee 用户,如下所示:
    chown apigee:apigee /opt/apigee/customer/application/message-processor.properties
    
  9. 重启消息处理器,如下所示:
    /opt/apigee/apigee-service/bin/apigee-service edge-message-processor restart
    
  10. 如果您有多个消息处理器,请在所有消息 处理器上重复上述步骤。

验证消息处理器上是否已将 405 属性的忽略允许标头设置为 false

本部分介绍了如何验证消息处理器上是否已成功将属性 HTTP.ignore.allow_header.for.405 更新为 false

即使您使用令牌 conf_http_HTTP.ignore.allow_header.for.405 在消息 处理器上更新值,也需要验证实际属性 HTTP.ignore.allow_header.for.405 是否已设置为 false

  1. 在消息处理器机器上,在 /opt/apigee/edge-message- processor/conf 目录中搜索属性 HTTP.ignore.allow_header.for.405,并检查其是否已设置为 false,如下所示:
    grep -ri "HTTP.ignore.allow_header.for.405" /opt/apigee/edge-message-processor/conf
    
  2. 如果该属性在消息处理器上成功更新,则上述命令 应在 http.properties 文件中将属性 HTTP.ignore.allow_header.for.405 的值显示为 false,如下所示:
    /opt/apigee/edge-message-processor/conf/http.properties:HTTP.ignore.allow_header.for.405=false
  3. 如果您仍然看到属性 HTTP.ignore.allow_header.for.405 的值为 true,请验证您是否已正确按照在 消息处理器上将 405 属性的忽略允许标头配置为 false 中列出的所有步骤操作。如果您遗漏了任何步骤,请再次正确重复所有步骤。
  4. 如果您仍然无法修改属性 HTTP.ignore.allow_header.for.405,请与 Apigee Edge 支持团队联系