Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Set-Cookie and Response Body not getting sent together

may
Bronze 5
Bronze 5

I'm having a problem that seems quite simple, to be honest, but I haven't been able to fix it.

Any help is appreciated, please.

So I get three cookies from the response, manipulate them (change the domain) and I have to set them as headers and send the response content from endpoint forward to the user.

Goal: send three Set-Cookies header + response.content in response body.

What I've tried: After some tests with AssignMessage, I realized that only the last Set-Cookie was being sent, but when I changed the name of the cookies, they all got sent. Because of that, I had three AssignMessage policies, each adding one header Set-Cookie. All of that is fine. The problem is that I've tried adding the <Payload> response.content in all of these policies and in a separeted policy and, for some reason, it doesn't get sent to the user in the response body. I've tried adding the response.content with RaiseFault, and it works, but then the three Set-Cookie headers don't show, even when I add the Set-Cookies only with the RaiseFault policy.

I'm sure there is a simple detail that I'm missing with these policies...

 

P.S.: I don't have access to the endpoint's code.

Thank you.

Solved Solved
0 1 1,747
1 ACCEPTED SOLUTION

It sounds to me like you are using Apigee to proxy to an HTTP service, not to an API.  That's not what Apigee is intended to do. Though it should work , it might not be easy.  Specifically, handling cookies and  modifying the domain of set-cookies is not normally a thing that an API gateway does. Though it's possible. (there are a lot of people who use Apigee for "non-standard" use cases)

By default, Apigee will send  the response content from the upstream system back to the original client. You don't need to do anything to the message to make that happen. 

If you want to modify the headers, you can do THAT with AssignMessage or with a JavaScript policy. 

What I might try: 

<AssignMessage name='AM-HackCookies'>
  <AssignVariable>
    <Name>orig-domain</Name>
    <Value>whatever</Value>
  </AssignVariable>
  <AssignVariable>
    <Name>new-domain</Name>
    <Value>something-else</Value>
  </AssignVariable>
  <Set>
    <Headers>
      <Header name='Set-Cookie'>{replaceAll(request.header.set-cookie.values.string, old-domain, new-domain)}</Header>
    </Headers>
  </Set>
</AssignMessage>

 

View solution in original post

1 REPLY 1

It sounds to me like you are using Apigee to proxy to an HTTP service, not to an API.  That's not what Apigee is intended to do. Though it should work , it might not be easy.  Specifically, handling cookies and  modifying the domain of set-cookies is not normally a thing that an API gateway does. Though it's possible. (there are a lot of people who use Apigee for "non-standard" use cases)

By default, Apigee will send  the response content from the upstream system back to the original client. You don't need to do anything to the message to make that happen. 

If you want to modify the headers, you can do THAT with AssignMessage or with a JavaScript policy. 

What I might try: 

<AssignMessage name='AM-HackCookies'>
  <AssignVariable>
    <Name>orig-domain</Name>
    <Value>whatever</Value>
  </AssignVariable>
  <AssignVariable>
    <Name>new-domain</Name>
    <Value>something-else</Value>
  </AssignVariable>
  <Set>
    <Headers>
      <Header name='Set-Cookie'>{replaceAll(request.header.set-cookie.values.string, old-domain, new-domain)}</Header>
    </Headers>
  </Set>
</AssignMessage>