在訊息處理工具中設定 405 屬性的允許允許標頭

您正在查看 Apigee Edge 說明文件。
查看 Apigee X 說明文件
資訊

在用戶端與伺服器通訊中,如果用戶端已知用戶端提供的 HTTP 要求方法,但目標資源不支援,則伺服器會傳回 HTTP 狀態碼 405 Method Not Allowed。在 Apigee Edge 中,後端伺服器也能以 HTTP 狀態碼 405 Method Not Allowed. 回應

Apigee Edge 預期後端伺服器會傳送 405 Method Not Allowed 回應,以及 Allow 標頭中允許的方法清單。根據 RFC 7231 的第 6.5.5 節:405 不允許的方法

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 標頭 (不含「Allow Gateway - Response 40」錯誤標頭)

不過,在某些情況下,後端可能無法修正後端,或是修改 API Proxy 來立即解決這個問題。

在這種情況下,您可以在訊息處理器層級暫時為 405 屬性 HTTP.ignore.allow_header.for.405 設定忽略允許標頭。如果將這項屬性設為 true,則即使後端伺服器傳送沒有 Allow 標頭的 HTTP 狀態碼 405 Method Not Allowed,Apigee 也無法向用戶端應用程式傳回 502 Bad Gateway 回應。

準備好修正後端伺服器,以便透過 Allow 標頭傳送 HTTP 狀態碼 405 Method Not Allowed 後,就可以將屬性 HTTP.ignore.allow_header.for.405 還原為預設值 false

事前準備

使用本文件中的步驟前,請務必瞭解下列主題:

在郵件處理器上將 405 屬性的忽略允許標頭設為 true

在 Apigee Edge 中,HTTP.ignore.allow_header.for.405 屬性預設為 false。如果後端伺服器在沒有 Allow 標頭的情況下傳送 HTTP 狀態碼 405 Method Not Allowed,此設定可讓 Apigee Edge 將錯誤代碼 protocol.http.Response405WithoutAllowHeader502 Bad Gateway 傳回用戶端應用程式。如要防止 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 支援團隊聯絡。