{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • Edge/API Management /
avatar image
0
Question by Ari Heber · Jan 21, 2020 at 01:20 PM · 525 Views assign message policyheadersassignmessage

AssignMessage - How can I get all headers ?

I'm using AssignMessage to generate a new HTTP request, and I want to put all headers of the original request in the payload of the new request.

From what I see in the variables-reference, I can only refer to a specific header (request.header.header_name.values).

How can I get a full list of all headers and their values?

Comment
Add comment
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Close

2 Answers

  • Sort: 
avatar image
0
Best Answer

Answer by Dino-at-Google   · Jan 21, 2020 at 10:51 PM

There is no way to read a single variable that contains, for example, all of the names and values of the inbound headers in a JSON format. If you want to embed the names and values of the inbound request headers into the payload of a new, different request, then you probably want to use a JavaScript callout to do so.

If I use this JavaScript in the response flow:

var rh = context.getVariable('request.headers.names');
context.proxyResponse.content = String(rh);

...then when invoking the API Proxy I see this result:

$ curl -i https://$ORG-$ENV.apigee.net/jstest-1/t1
HTTP/1.1 200 OK
Date: Tue, 21 Jan 2020 22:42:45 GMT
Content-Type: text/plain
Content-Length: 80
Connection: keep-alive


[Accept, Host, User-Agent, X-Forwarded-For, X-Forwarded-Port, X-Forwarded-Proto]


What you're seeing there is the response payload contains a stringified version of the list of request header NAMES.

If instead I use this Javascript:

var rh = context.getVariable('request.headers.names');
var s = String(rh);
// convert the list of header names to an array:
var list = s.substring(1, s.length - 1).split(new RegExp(', ', 'g'));
var hash = {};
list.forEach(function(headerName) {
  hash[headerName] = context.getVariable('request.header.' + headerName);
});
context.proxyResponse.content = JSON.stringify(hash, null, 2);

Then the response payload is more like this:

{
    "Accept": "*/*",
    "Host": "gaccelerate3-test.apigee.net",
    "User-Agent": "curl/7.61.1",
    "X-Forwarded-For": "54.14.13.16",
    "X-Forwarded-Port": "443",
    "X-Forwarded-Proto": "https"
}

AFAIK you cannot do that with AssignMessage.

Comment
Add comment Show 2 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ari Heber · Jan 22, 2020 at 11:57 AM 0
Link

Thanks alot @Dino-at-Google.

Please note that your code is ignoring multi-values headers.

avatar image Dino-at-Google ♦♦ Ari Heber   · Jan 22, 2020 at 05:18 PM 0
Link

Yes, that is correct. To handle Multi-valued headers you'll have to add a little bit more logic.

avatar image
0

Answer by Jayesh Upadhyay · Jan 21, 2020 at 04:47 PM

Hi @Ari Heber

Please refer to following section of Assign message documentation page.

https://docs.apigee.com/api-platform/reference/policies/assign-message-policy#assignto


In your AssignMessage Policy under AssignTo section if you configure it correctly (createNew attibute value is set to false) you don't need to copy headers from original request and it will use the headers form source request and pass it on to target back end.Following line in your assign message policy should do that.


<AssignTo createNew="false" transport="http" type="request"/>

Comment
Add comment Show 1 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ari Heber · Jan 21, 2020 at 05:06 PM 0
Link

Thanks Jayesh.

I am trying to put the headers of the original request in the payload of the new request. I do not want to use them as "headers" of the new request.

Is there a way to get it as an array ?

Follow this Question

Answers Answers and Comments

73 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing a JSON payload "on the fly" 1 Answer

how to populate the Time unit in header ? 2 Answers

Path suffix not writing variables in new url 1 Answer

CORS Error : header contains multiple values '*, *', but only one is allowed 2 Answers

Remove one item from multivalue header 1 Answer

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges