How can we retain host header from inbound request

Not applicable

Hi,

I am trying to send a request header in my Inbound request, but this header gets overriden by Apigee and always points to the specified virtualhost hostname.

I tried setting the following property in target endpoint propert

<Property name="request.retain.headers">Host</Property>

But this doesnt seem to solve my problem.

Can someone please help me out to resolve this issue?

Regards,

Anil

Solved Solved
2 16 5,129
1 ACCEPTED SOLUTION

Not applicable

@sreeharsha.r,

You could manually override the Host header value for the target by setting the variable 'target.header.host'. This should be done in the target request flow.

Setup an AssignMessage or JavaScript policy that assigns the value of request.header.host to target.header.host.

-Dave

View solution in original post

16 REPLIES 16

adas
Participant V

@sreeharsha.r Are you trying this on the cloud or on-premise ? If you are on-premise then you might want to modify couple of properties on the message-processor's http.properties:

HTTP.retain.headers=Host

# possible values are useFirst, useLast, allowDuplicates, multiValued

# if value is empty, then all options useFirst, useLast, allowDuplicates, multiValued are false

# for any header that is not configured here:

HTTPHeader.Host=multiValued

Thanks for the quick response Arghya. Yes i have an On-Prem installation of Apigee. I tried all of these configuration with server restarts.

HTTP.retain.headers=Content-Type,Connection,Content-Encoding,Transfer-Encoding,Content-Length,XTestId,Host

HTTPHeader.Host=useFirst/ useLast/ allowDuplicates/ multiValuedmultiValued/ allowDuplicates, multiValuedmultiValued

But in all the cases my Host header was overridden, without any change to the behavior.

I have also done the following in my target endpoint property configuration

<Property name="request.retain.headers">Host</Property>

<Property name="request.retain.headers.enabled">true</Property>

Am i missing some configurations or doing it wrongly or is it a Bug?

Where are you overriding the host header? It sounds like your overriding it on the client side (inbound request)? Or are you trying to modify it within the proxy flow? If the latter, which flow? If the former, can you clarify? When I try to do that it won't hit my test proxy.

I have to send a header named "Host" from my Client application to a Backend server. When i send it from the client, the request that i receive on my backend has the Host header but it is overridden by the OPDK server Host details. I want to retain this header value that is sent from the client.

adas
Participant V

Would you mind sharing your proxy. Email me the proxy and your properties file at adas@apigee.com

It would be hard to comment on the behaviour without looking at the proxy.

Not applicable

sreeharsha.r , do you have a load balancer in front of the routers ? probably its dropping the header that you are sending and adding the host header required by the Virtualhost to hit the routers .

Check the router logs too to get more information

adas
Participant V

Hi @sreeharsha.r,

Nothing wrong with the proxy. I tried the same proxy and set the host header in the response using a javascript policy (using your proxy) and it works fine when I bypass the ELB. When I make requests via the ELB, I can see the host header being sent by the MP but its getting chopped by the ELB. When I bypass the ELB and make the api request directly against the routers, I get the host header back. So it's the load balancer which is removing the host header.

@arghya das, @Maruti Chand

Ok let me make it clear, I am trying to pass a host header in the request. I tried two scenarios to achieve this.

1. Passed the header from the client

2. Set the request header using JS policy

But in both cases the request i receive on my backend has a different host header (which is the host name of the router). Is there no-ways i can send a host header other then the router host? Why is apigee server overriding this value?

Is there some configuration i need to do to enforce this?

adas
Participant V

Ok. The javascript policy in your proxy was setting response.header.host so I was confused. If you use the attached proxy you would be able to send the custom host header using the javascript policy:

425-host-header-apigee.png

This means the host header is being sent to the backend. But please note that apigee routers use the host header to classify the request, so even if you send a host header from the client side which is not the virtualhost's hostalias, then the request would fail with a 404. Setting the host header in the javascript or assign message policy is still an option.forward-test-sap-rev1-2015-05-12-1.zip

Yes, this is exactly what i assumed. I saw the Host header being set in the trace session. But when i get this request in the backend server the host header always contains the origin host details and not the one seen in trace session.

If i do a curl for the same backend passing host header i get the header as is, this is what we expect using a API Proxy as well. It should not override the header value.

Not applicable

@sreeharsha.r,

You could manually override the Host header value for the target by setting the variable 'target.header.host'. This should be done in the target request flow.

Setup an AssignMessage or JavaScript policy that assigns the value of request.header.host to target.header.host.

-Dave

I tried this now and it works, Thanks Dave!

Hi @Dave Newman,

We are facing the same issue and we followed the same steps suggested by you, but we are getting 400 - bad request. Can you help us out on the same !

jhans
Participant II

Hello Anil,

As discussed attached is the bundle which works for setting host header for target. As described by Dave earlier we have to use target.header.host.

I have tested this with Apache server and was able to see the host header changed.

Regards,

Jagjyot

jhans
Participant II

Hey @jagjyot

We are facing the same issue and we followed the same steps suggested by you, but we are getting 400 - bad request. Can you help us out on the same !