You're viewing Apigee Edge documentation.
Go to the
Apigee X documentation. info
Symptom
The client application gets an HTTP status code of 502 Bad Gateway
with error code
protocol.http.DuplicateHeader
as a response for API calls.
Error message
Client application gets the following response code:
HTTP/1.1 502 Bad Gateway
In addition, you may observe an error message similar to the one shown below:
{ "fault":{ "faultstring":"Duplicate Header \"Expires\"", "detail":{ "errorcode":"protocol.http.DuplicateHeader" } } }
Possible Causes
This error occurs if a specific HTTP header that is not allowed to have duplicates in Apigee Edge, appears more than once with same or different values, as part of the HTTP response sent by the backend server to Apigee Edge.
As per
RFC 7230, section 3.2.2: Field Order, a sender MUST NOT generate multiple header
fields with the same field name in a message unless either the entire field value for that
header field is defined as a comma-separated list, [i.e., #(values)] or the header field is a
well-known exception. If Apigee Edge finds that a specific same header, that is not allowed to
have duplicates, is sent more than once in the HTTP response sent by the
target/backend server,
then it responds with 502 Bad Gateway
and error code
protocol.http.DuplicateHeader
Here are the possible causes for this error:
Cause | Description | Troubleshooting instructions applicable for |
---|---|---|
Duplicate header in response | The response from the backend server contains duplicate headers. | Edge Public and Private Cloud users |
Common diagnosis steps
Use one of the following tools/techniques to diagnose this error:
API Monitoring
To diagnose the error using API Monitoring:
- Sign in to Apigee Edge UI as a user with an appropriate role.
Switch to the organization in which you want to investigate the issue.
- Navigate to the Analyze > API Monitoring > Investigate page.
- Select the specific timeframe in which you observed the errors.
- Ensure that the Proxy filter is set to All.
- Plot Fault Code against Time.
Select a cell which has the fault code
protocol.http.DuplicateHeader
as shown below:Information about the fault code
protocol.http.DuplicateHeader
is displayed as shown below:- Ensure that the Status Code is
502
as shown in the above example. - Click View logs and expand the row for the failed request.
From the Logs window, note the following details:
- Status Code:
502
- Fault Source:
target
- Fault Code:
protocol.http.DuplicateHeader
.
- Status Code:
- The Fault Source is
target
, which indicates that the response from the backend server contained duplicate headers.
Trace tool
To diagnose the error using the Trace tool:
- Enable the trace session and either
- Wait for the
502 Bad Gateway
error to occur or - If you can reproduce the issue, make the API call and reproduce the
502 Bad Gateway
error
- Wait for the
Ensure Show all Flow Infos is enabled:
- Select one of the failing requests and examine the trace.
- Navigate through different phases of the trace and locate where the failure occurred.
You will find the error typically in a flow after the Request sent to target server phase as shown below:
Note the value of the error from the trace.
The above sample trace shows the error as
Duplicate Header "Expires"
. Since the error is raised by Apigee after the request was sent to the backend server, it indicates that the backend server sent the headerExpires
more than once.- Navigate to the AX (Analytics Data Recorded) Phase in the trace and click on it.
Scroll down to the Phase Details - Response Headers section and determine the values of X-Apigee-fault-code and X-Apigee-fault-source as shown below:
- You will see the values of X-Apigee-fault-code and X-Apigee-fault-source
as
protocol.http.DuplicateHeader
andtarget
, indicating that this error is caused because duplicate headers were passed by the backend server for the response headerExpires
.Response Headers Value X-Apigee-fault-code protocol.http.DuplicateHeader
X-Apigee-fault-source target
Check if you are using proxy chaining; that is, if the target server or target endpoint is invoking another proxy in Apigee.
To determine this, navigate back to the Request sent to target server phase. Click Show Curl.
The Curl for Request Sent to Target Server window opens from which you can determine the target server host alias.
- If the target server host alias is pointing to a virtual host alias, then it is proxy
chaining. In this case, you need to repeat all the above steps for the chained proxy until
you determine what is actually causing the
502 Bad Gateway
error. - If the target server host alias points to your backend server, then it indicates that your backend server is sending the duplicate headers in the response to Apigee.
NGINX
To diagnose the error using NGINX access logs:
- If you are a Private Cloud user, then you can use NGINX access logs to
determine the key information about HTTP
502
errors. Check the NGINX access logs:
/opt/apigee/var/log/edge-router/nginx/ORG~ENV.PORT#_access_log
Where: ORG, ENV and, PORT# are replaced with actual values.
- Search to see if there are any
502
errors during a specific duration (if the problem happened in the past) or if there are any requests still failing with502
. If you do find any
502
errors with the X-Apigee-fault-code matching the value ofprotocol.http.DuplicateHeader
, then determine the value of the X-Apigee-fault-source.Sample 502 error from NGINX access log:
The above sample entry from NGINX Access log has the following values for X- Apigee-fault-code and X-Apigee-fault-source:
Response Headers Value X-Apigee-fault-code protocol.http.DuplicateHeader
X-Apigee-fault-source target
Cause: Duplicate Header in response
Diagnosis
- Determine the Fault Code and Fault Source for the error observed using API Monitoring or NGINX access logs as explained in Common diagnosis steps.
- If the Fault Source has the value
target
, then this indicates that the response sent by the target server contains duplicate headers. You can determine the actual header that is sent more than once as part of the response using one of the following methods:
Error message
Using the error message:
If you have access to the complete error message received from Apigee Edge, then refer to the
faultstring
. Thefaultstring
contains the header name that has been sent more than once.Sample error message:
"faultstring":"Duplicate Header \"Expires\""
- In the above error message, you can see that the header
Expires
is sent more than once as seen in thefaultstring
.
Actual request
Using the actual request:
- If you don’t have access to the actual request made to the target server, then get
the corresponding
curl
command from Using the Trace tool step 10.a and step 10.b. If you have access to the actual request made to the target server application, then perform the following steps:
Make a call to the target server.
Sample Request for the target server used in this example:
curl -X GET "https://BACKEND_SERVER_HOST/response-headers?Expires=Mon%2C%2021%20June%202021%2007%3A28%3A00%20GMT&Expires=Mon%2C%2021%20June%202021%2007%3A28%3A00%20GMT" -v
Verify the list of headers seen in the response.
Sample Response from the target server used in this example:
* ...Trimmed... > GET /response-headers?Expires=Mon%2C%2021%20June%202021%2007%3A28%3A00%20GMT&Expires=Mon%2C%2021%20June%202021%2007%3A28%3A00%20GMT HTTP/2 > Host: BACKEND_SERVER_HOST > User-Agent: curl/7.64.1 > Accept: */* > * Connection state changed (MAX_CONCURRENT_STREAMS == 128)! < HTTP/2 200 < date: Fri, 02 Jul 2021 05:29:07 GMT < content-type: application/json < content-length: 166 < server: gunicorn/19.9.0 < Expires: Mon, 21 June 2021 07:28:00 GMT < Expires: Mon, 21 June 2021 07:28:00 GMT < access-control-allow-origin: * < access-control-allow-credentials: true < ----<Response BODY>------ * Connection #0 to host httpbin.org left intact * Closing connection 0
In the above example request, the header
Expires
is sent more than once. Therefore, this request fails with the502 Bad Gateway
error and the error code:protocol.http.DuplicateHeader
.If the header whose name appears in the
faultstring
appears more than once in the backend server’s response, then that’s the cause for this error. In the above case, the headerExpires
is sent more than once.
Resolution
Fix duplication
Option #1 [Recommended Option] Fix the backend server to not include duplicate headers
- Analyze the reason for the specific backend server to send duplicate header
Expires
and verify whether it is okay for the API proxies to accept that. In most cases, it will not be desirable as per HTTP specification RFC7230. - If it is not desirable, modify your target server application not to send duplicate headers.
In the example discussed above, it is noticed that header
Expires
is sent twice with the same value, which is not desirable. You can fix the issue by making sure that the target server passes theExpires
header only once. - If it is desirable and you want to allow the duplicate headers, go to Option #2 Using CwC property.
CwC
Option #2 Using CwC property
Apigee provides a CwC property
HTTPHeader.<HeaderName>
,which allows client applications and target
servers to send duplicate headers to API proxies in Apigee Edge.
CwC property | Values |
---|---|
HTTPHeader.<HeaderName> |
allowDuplicates,multivalued |
For example, the following property can be set on the Message Processors to allow duplicates
and multiple values for the header Expires
.
HTTPHeader.Expires=allowDuplicates, multiValued
- If you are a Private Cloud user, you can configure the property to prevent Apigee
Edge from raising a
502 Bad Gateway
error, even if the request contains duplicate headers using the Configuring Message Processors to use duplicate headers how-to guide. - If you are a Public Cloud user, contact Apigee Edge Support to configure this property for your organization.
Specification
Apigee responds with the 502 Bad Gateway
error response as it expects that the
backend server would behave according to the following RFC specifications:
Specification |
---|
RFC 7230, section 3.2.2: Field Order |
RFC 7230, section 3.2: Header Fields |
If you still need any assistance from Apigee Support, go to Must gather diagnostic information.
Must gather diagnostic information
Gather the following diagnostic information, and then contact Apigee Edge Support.
If you are a Public Cloud user, provide the following information:
- Organization name
- Environment name
- API Proxy name
- Complete
curl
command used to reproduce the502
error - Trace file for the API requests
If you are a Private Cloud user, provide the following information:
- Complete error message observed for the failing requests
- Environment name
- API proxy bundle
- Trace file for the API requests
NGINX access logs:
/opt/apigee/var/log/edge-router/nginx/ORG~ENV.PORT#_access_log
Where: ORG, ENV and PORT# are replaced with actual values.
- Message Processor system logs
/opt/apigee/var/log/edge-message-processor/logs/system.log