"Host" header doesn't get passed onto the target service deployed on kubernetes

We have a proxy with a policy step of Assigned "Host" header and we added a AssignMessage like this

<Add>
   <Headers>
      <Header name="Host">*host-url-here*</Header>
   </Headers>
</Add>

But somehow the "Host" header does not get passed on to the target service (deployed on kubernetes). Looks like the Message Processor strips off the header. Any steps/documentation to resolve this?

Solved Solved
0 7 5,252
1 ACCEPTED SOLUTION

Dear @Anvi,


Whatever value you set in AssignMessage will be captured in “message” variables, which will be passed to MP but some reserved values, including “host”, may not be forwarded to end target.

More details on the different types of variables (target, message, response, etc..) are described at Apigee Doc - Variables reference

If you want to pass a host value to your end target, you can use a small JS script to assign value in "target.header.host". Follow the instruction in this post (2015 and relevant).

Download the sample bundle shared in that post to see how it is implemented.

View solution in original post

7 REPLIES 7

Hi @Anvi, did you check the Trace session?

Try using Set tag of AssignMessage Policy instead of Add.

<Set>
   <Headers>
      <Header name="Host">*host-url-here*</Header>
   </Headers>
</Set>

That doesn't seem to work either.

7231-setting-host-header.png

In the above example you can see that the header is being set though the request to the target service it's missing it.

I'm attaching the example proxy header-example-echo-rev1-2018-08-06.zip

We also tried with this solution though that's from 2015 and it doesn't seem to work anymore.

Dear @Anvi,


Whatever value you set in AssignMessage will be captured in “message” variables, which will be passed to MP but some reserved values, including “host”, may not be forwarded to end target.

More details on the different types of variables (target, message, response, etc..) are described at Apigee Doc - Variables reference

If you want to pass a host value to your end target, you can use a small JS script to assign value in "target.header.host". Follow the instruction in this post (2015 and relevant).

Download the sample bundle shared in that post to see how it is implemented.

Hi @Brendan,

We tried that before though it doesn't seem to work.

7263-setting-target-header-host.png

7264-curl-request.png

Any idea why it doesn't work?

Curl request UI doesnot display some of the values in header, so you may not see "Host" there.

A better way to verify is to use http://mocktarget.apigee.net/echo which simply echoes back whatever values being passed in.

Attached is my trace result. My end target is http://mocktarget.apigee.net/echo .

7266-target-header-host-assigned.png

7267-request-sent-to-target.png

7268-target-response.png

You may want to put debug log on your own target to view exactly what "host" being sent to your target.

mrios
New Member

Thanks @Brendan!

I was using the same echo endpoint but after looking at your screenshot I found that I was setting the header in the preflow of the proxy endpoint instead of the preflow of the target endpoint, that make it work.

Cool. If this helps, please upvote the solution so others can benefit.

Thanks @Matias.