microgateway response header in onend_response ?

robinm
New Member

Hi guys.

I have been fighting this for a while and am not winning.

It is highly likely that I have no clue as to what I am doing ... 🙂 🙂

onend_response: function(req, res, data, next) {

   res.setHeader('onend_response', 'nothing happens');

   next(null,data);
}

Is this possible - or must all headers be written in the "onresponse" function ?

( I am able to set response headers quite happily there. )


					
				
			
			
				
			
			
				
Solved Solved
0 3 226
2 ACCEPTED SOLUTIONS

Former Community Member
Not applicable

Hey Robin,

Setting the header as you have should work. The only change I'd make is to call "next" with parameters. Please let me know if you made progress.

View solution in original post

robinm
New Member

The log error gave the answer in this case

stack=Error: 'Cant set headers after they are sent.'  at
ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:357:11)  at onend_response

Headers are sent once the first portion of the response content is been sent.

In order to set a header in this section, I was forced to code the "ondata_response" section, saving the data chunks and not passing any data until the end, calling next(null, null) in that section.

The chunks needed to be concatenated in the response section as shown in other posts and doc.

View solution in original post

3 REPLIES 3

Former Community Member
Not applicable

Hey Robin,

Setting the header as you have should work. The only change I'd make is to call "next" with parameters. Please let me know if you made progress.

I am reflecting current body in the line "next(null,data);"

How would you change that ?

robinm
New Member

The log error gave the answer in this case

stack=Error: 'Cant set headers after they are sent.'  at
ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:357:11)  at onend_response

Headers are sent once the first portion of the response content is been sent.

In order to set a header in this section, I was forced to code the "ondata_response" section, saving the data chunks and not passing any data until the end, calling next(null, null) in that section.

The chunks needed to be concatenated in the response section as shown in other posts and doc.